diff --git a/apps/synapse-oauth-signin/package.json b/apps/synapse-oauth-signin/package.json index 52a9234775..66bf79ee75 100644 --- a/apps/synapse-oauth-signin/package.json +++ b/apps/synapse-oauth-signin/package.json @@ -22,6 +22,7 @@ "react-dom": "^18.2.0", "react-router-dom": "^5.3.4", "sass": "^1.71.1", + "universal-cookie": "^4.0.4", "synapse-react-client": "workspace:*" }, "devDependencies": { diff --git a/apps/synapse-oauth-signin/src/AppInitializer.tsx b/apps/synapse-oauth-signin/src/AppInitializer.tsx index 440e12ac1a..0ff574fb74 100644 --- a/apps/synapse-oauth-signin/src/AppInitializer.tsx +++ b/apps/synapse-oauth-signin/src/AppInitializer.tsx @@ -6,12 +6,18 @@ import { SynapseConstants, } from 'synapse-react-client' import { handleErrorRedirect } from './URLUtils' +import UniversalCookies from 'universal-cookie' +const cookies = new UniversalCookies() function AppInitializer( props: React.PropsWithChildren>, ) { + const accountSitePrompted = cookies.get( + SynapseConstants.ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY, + ) == 'true' // short-lived cookie const urlSearchParams = new URLSearchParams(window.location.search) - const prompt = urlSearchParams.get('prompt') + const prompt = + accountSitePrompted ? 'none' : urlSearchParams.get('prompt') let maxAge = undefined // check max age when re-establishing the session, not to auto-consent. diff --git a/packages/synapse-react-client/src/utils/AppUtils/AppUtils.ts b/packages/synapse-react-client/src/utils/AppUtils/AppUtils.ts index 56b58ec571..f7b5f9a301 100644 --- a/packages/synapse-react-client/src/utils/AppUtils/AppUtils.ts +++ b/packages/synapse-react-client/src/utils/AppUtils/AppUtils.ts @@ -1,5 +1,8 @@ import { useHistory } from 'react-router-dom' -import { LAST_PLACE_LOCALSTORAGE_KEY } from '../SynapseConstants' +import { + ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY, + LAST_PLACE_LOCALSTORAGE_KEY, +} from '../SynapseConstants' import { useEffect, useState } from 'react' import UniversalCookies from 'universal-cookie' @@ -33,6 +36,16 @@ export function storeRedirectURLForOneSageLoginAndGotoURL(href: string) { } export function processRedirectURLInOneSage() { + // PORTALS-3299 : Indicate that we have completed the login workflow (cookie expires in a minute) to break out of a cycle + const expireDate = new Date() + expireDate.setMinutes(expireDate.getMinutes() + 1) + const hostname = window.location.hostname.toLowerCase() + cookies.set(ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY, 'true', { + path: '/', + expires: expireDate, + domain: hostname.endsWith('.synapse.org') ? 'synapse.org' : undefined, + }) + if (cookies.get(ONE_SAGE_REDIRECT_COOKIE_KEY)) { const href = cookies.get(ONE_SAGE_REDIRECT_COOKIE_KEY) cookies.remove(ONE_SAGE_REDIRECT_COOKIE_KEY) diff --git a/packages/synapse-react-client/src/utils/SynapseConstants.ts b/packages/synapse-react-client/src/utils/SynapseConstants.ts index df749f3d4d..c42c8ecabd 100644 --- a/packages/synapse-react-client/src/utils/SynapseConstants.ts +++ b/packages/synapse-react-client/src/utils/SynapseConstants.ts @@ -186,6 +186,9 @@ export const ACCESS_TOKEN_COOKIE_KEY = 'org.sagebionetworks.security.user.login.token' export const LAST_PLACE_LOCALSTORAGE_KEY = 'last_place_url' +export const ACCOUNT_SITE_PROMPTED_FOR_LOGIN_COOKIE_KEY = + 'org.sagebionetworks.account.promptedforlogin' + /* Persistent localStorage keys on SWC logout */ export const PERSISTENT_LOCAL_STORAGE_KEYS = [ ...ORIENTATION_BANNER_KEYS, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c11a908268..9ecdcd38f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -854,6 +854,9 @@ importers: synapse-react-client: specifier: workspace:* version: link:../../packages/synapse-react-client + universal-cookie: + specifier: ^4.0.4 + version: 4.0.4 devDependencies: '@sage-bionetworks/synapse-types': specifier: workspace:*