From 36f4f9ff52d26a28f2951cc46a83bfd99573da24 Mon Sep 17 00:00:00 2001 From: jay-hodgson Date: Fri, 25 Oct 2024 12:29:11 -0700 Subject: [PATCH] SWC-7133: edge case where refreshing the session is interrupted --- .../session/ApplicationSessionManager.tsx | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx b/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx index ce13b0d34f..e644cc7988 100644 --- a/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx +++ b/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx @@ -8,6 +8,8 @@ import { ApplicationSessionContextProvider } from './ApplicationSessionContext' import { SynapseContextProvider, SynapseContextType } from '../../context' import dayjs from 'dayjs' import { useTermsOfServiceStatus } from '../../../synapse-queries/termsOfService/useTermsOfService' +import { PresentToAll } from '@mui/icons-material' +import { TermsOfServiceState } from '@sage-bionetworks/synapse-types' export type ApplicationSessionManagerProps = React.PropsWithChildren<{ downloadCartPageUrl?: string @@ -109,18 +111,23 @@ export function ApplicationSessionManager( setToken(token) setHasInitializedSession(true) try { - // get the user profile - await SynapseClient.getUserProfile(token) + // get the user terms of service status + await SynapseClient.getTermsOfServiceStatus(token) } catch (e) { - if (e && e.reason != 'Terms of use have not been signed.') { - console.error('Error on refreshSession: ', e) - // intentionally calling sign out because the token could be stale so we want - // the stored session to be cleared out. - SynapseClient.signOut().then(() => { - // PORTALS-2293: if the token was invalid (caused an error), reload the app to ensure all children - // are loading as the anonymous user - window.location.reload() - }) + console.error('Error on refreshSession: ', e) + // if status number field is present, then + //if 400 level, then clear + if ('status' in e && typeof e['status'] === 'number') { + const status = e['status'] + if (status >= 400 && status < 500) { + // intentionally calling sign out because the token could be stale so we want + // the stored session to be cleared out. + SynapseClient.signOut().then(() => { + // PORTALS-2293: if the token was invalid (caused an error), reload the app to ensure all children + // are loading as the anonymous user + window.location.reload() + }) + } } } }, [initAnonymousUserState, maxAge])