From 8e45eaca19b97c2863081ddb900c4f86cbd5b322 Mon Sep 17 00:00:00 2001 From: jay-hodgson Date: Tue, 22 Oct 2024 14:43:35 -0700 Subject: [PATCH] PORTALS-3293: Fix access token issue, as well as discrepancy in API design doc (field renamed during backend implementation) --- apps/SageAccountWeb/src/AppInitializer.tsx | 2 +- .../src/components/SignUpdatedTermsOfUsePage.tsx | 9 +++++++-- .../src/mocks/termsOfService/mockTermsOfService.ts | 8 ++++---- .../synapse-queries/termsOfService/useTermsOfService.ts | 3 ++- .../utils/AppUtils/session/ApplicationSession.test.tsx | 4 ++-- .../utils/AppUtils/session/ApplicationSessionManager.tsx | 3 +-- packages/synapse-types/src/TermsOfService.ts | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/SageAccountWeb/src/AppInitializer.tsx b/apps/SageAccountWeb/src/AppInitializer.tsx index a435d95c5a4..3e7772b1cb7 100644 --- a/apps/SageAccountWeb/src/AppInitializer.tsx +++ b/apps/SageAccountWeb/src/AppInitializer.tsx @@ -77,7 +77,7 @@ function AppInitializer(props: { children?: React.ReactNode }) { let redirectRoute = undefined if (termsOfServiceStatus) { if ( - termsOfServiceStatus.usersCurrentTermsOfServiceState != + termsOfServiceStatus.userCurrentTermsOfServiceState != TermsOfServiceState.UP_TO_DATE && skippedSigningUpdatedToS === false ) { diff --git a/apps/SageAccountWeb/src/components/SignUpdatedTermsOfUsePage.tsx b/apps/SageAccountWeb/src/components/SignUpdatedTermsOfUsePage.tsx index e698b0241c7..e21872d75ed 100644 --- a/apps/SageAccountWeb/src/components/SignUpdatedTermsOfUsePage.tsx +++ b/apps/SageAccountWeb/src/components/SignUpdatedTermsOfUsePage.tsx @@ -28,10 +28,15 @@ export const SignUpdatedTermsOfUsePage = ( const { mutate: signTermsOfService } = SynapseQueries.useSignTermsOfService() const { data: tosInfo } = SynapseQueries.useTermsOfServiceInfo() - const { data: tosStatus } = SynapseQueries.useTermsOfServiceStatus() + const { data: tosStatus } = SynapseQueries.useTermsOfServiceStatus( + accessToken, + { + enabled: !!accessToken, + }, + ) const isSkipAvailable = - tosStatus?.usersCurrentTermsOfServiceState == + tosStatus?.userCurrentTermsOfServiceState == TermsOfServiceState.MUST_AGREE_SOON const onSignTermsOfUse = async (event: React.SyntheticEvent) => { event.preventDefault() diff --git a/packages/synapse-react-client/src/mocks/termsOfService/mockTermsOfService.ts b/packages/synapse-react-client/src/mocks/termsOfService/mockTermsOfService.ts index a952e42f6a8..b4fd8f96a42 100644 --- a/packages/synapse-react-client/src/mocks/termsOfService/mockTermsOfService.ts +++ b/packages/synapse-react-client/src/mocks/termsOfService/mockTermsOfService.ts @@ -17,26 +17,26 @@ export const termsOfServiceNewUserStatus: TermsOfServiceStatus = { userId: '12345', lastAgreementDate: null, lastAgreementVersion: null, - usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, + userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, } export const termsOfServiceUpdatedMustAgreeNowStatus: TermsOfServiceStatus = { userId: '12345', lastAgreementDate: '2024-09-15T12:34:56Z', lastAgreementVersion: '2.0.0', - usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, + userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, } export const termsOfServiceUpdatedMustAgreeSoonStatus: TermsOfServiceStatus = { userId: '12345', lastAgreementDate: '2024-09-15T12:34:56Z', lastAgreementVersion: '2.0.0', - usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_SOON, + userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_SOON, } export const termsOfServiceUpToDateStatus: TermsOfServiceStatus = { userId: '12345', lastAgreementDate: '2024-09-15T12:34:56Z', lastAgreementVersion: '2.0.0', - usersCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE, + userCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE, } diff --git a/packages/synapse-react-client/src/synapse-queries/termsOfService/useTermsOfService.ts b/packages/synapse-react-client/src/synapse-queries/termsOfService/useTermsOfService.ts index b37c56e2d68..a9af8ad8b74 100644 --- a/packages/synapse-react-client/src/synapse-queries/termsOfService/useTermsOfService.ts +++ b/packages/synapse-react-client/src/synapse-queries/termsOfService/useTermsOfService.ts @@ -29,9 +29,10 @@ export function useTermsOfServiceInfo( } export function useTermsOfServiceStatus( + accessToken?: string, //usually we can fetch the access token from the context, but this hook is used by ApplicationSessionManager which sets the access token in the context (ApplicationSessionContextProvider)! options?: Partial>, ) { - const { accessToken, keyFactory } = useSynapseContext() + const { keyFactory } = useSynapseContext() return useQuery({ ...options, queryKey: keyFactory.getTermsOfServiceStatus(), diff --git a/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSession.test.tsx b/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSession.test.tsx index df2bfd3bb9f..cca52611747 100644 --- a/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSession.test.tsx +++ b/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSession.test.tsx @@ -67,7 +67,7 @@ const EXPECTED_ANONYMOUS_STATE: Partial = { } const TERMS_OF_SERVICE_STATUS_UP_TO_DATE: TermsOfServiceStatus = { userId: `${MOCK_USER_ID}`, - usersCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE, + userCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE, lastAgreementDate: '', lastAgreementVersion: '0.0.0', } @@ -81,7 +81,7 @@ const EXPECTED_AUTH_STATE: Partial = { const TERMS_OF_SERVICE_STATUS_MUST_AGREE_NOW: TermsOfServiceStatus = { userId: `${MOCK_USER_ID}`, - usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, + userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW, lastAgreementDate: '', lastAgreementVersion: '0.0.0', } 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 3207feb09a2..ce13b0d34f7 100644 --- a/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx +++ b/packages/synapse-react-client/src/utils/AppUtils/session/ApplicationSessionManager.tsx @@ -74,10 +74,9 @@ export function ApplicationSessionManager( setHasInitializedSession(true) }) }, [onNoAccessTokenFound]) - const { data: tosStatus } = useTermsOfServiceStatus({ + const { data: tosStatus } = useTermsOfServiceStatus(token, { enabled: !!token, }) - const refreshSession = useCallback(async () => { setTwoFactorAuthSSOError(undefined) let token diff --git a/packages/synapse-types/src/TermsOfService.ts b/packages/synapse-types/src/TermsOfService.ts index 40f9390d888..2769df965c7 100644 --- a/packages/synapse-types/src/TermsOfService.ts +++ b/packages/synapse-types/src/TermsOfService.ts @@ -15,7 +15,7 @@ export type TermsOfServiceStatus = { userId: string // The ID of the user lastAgreementDate?: string | null // The date/time when the user last agreed to the ToS, or null if never agreed lastAgreementVersion?: string | null // The version of ToS the user last agreed to, or null if never agreed - usersCurrentTermsOfServiceState: TermsOfServiceState // Defines the user's current ToS state. Used to guide the UI in what the user needs to do with their ToS agreements. This will always be provided. + userCurrentTermsOfServiceState: TermsOfServiceState // Defines the user's current ToS state. Used to guide the UI in what the user needs to do with their ToS agreements. This will always be provided. } export enum TermsOfServiceState {