From d0591b538699d3453ee5ab09288e42d04149742e Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:43:41 -0800 Subject: [PATCH 01/13] Revert "Revert "feat(auth): Enable resumable SignIn" (#13855)" This reverts commit b26e7199d25cbc1821ff7c45b8ad78b5544b7a2f. --- .github/integ-config/integ-all.yml | 14 + .../providers/cognito/signInResumable.test.ts | 268 ++++++++++++++++++ .../cognito/signInStateManagement.test.ts | 3 +- .../cognito/signInWithRedirect.test.ts | 15 +- .../src/client/utils/store/signInStore.ts | 112 +++++++- .../providers/cognito/apis/confirmSignIn.ts | 5 +- .../cognito/apis/signInWithCustomAuth.ts | 8 +- .../cognito/apis/signInWithCustomSRPAuth.ts | 8 +- .../providers/cognito/apis/signInWithSRP.ts | 9 +- .../cognito/apis/signInWithUserPassword.ts | 9 +- packages/aws-amplify/package.json | 6 +- .../storage/SyncSessionStorage.test.ts | 80 ++++++ .../storage-mechanisms-node-runtime.test.ts | 29 -- packages/core/src/index.ts | 1 + .../core/src/storage/SyncKeyValueStorage.ts | 59 ++++ .../core/src/storage/SyncSessionStorage.ts | 14 + packages/core/src/storage/index.ts | 2 + packages/core/src/types/storage.ts | 7 + 18 files changed, 581 insertions(+), 68 deletions(-) create mode 100644 packages/auth/__tests__/providers/cognito/signInResumable.test.ts create mode 100644 packages/core/__tests__/storage/SyncSessionStorage.test.ts delete mode 100644 packages/core/__tests__/storage/storage-mechanisms-node-runtime.test.ts create mode 100644 packages/core/src/storage/SyncKeyValueStorage.ts create mode 100644 packages/core/src/storage/SyncSessionStorage.ts diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 4759997ee29..34736a01399 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -609,6 +609,20 @@ tests: sample_name: [subdomains] spec: subdomains browser: [chrome] + - test_name: integ_next_custom_auth + desc: 'Sign-in with Custom Auth flow' + framework: next + category: auth + sample_name: [custom-auth] + spec: custom-auth + browser: *minimal_browser_list + - test_name: integ_next_auth_sign_in_with_sms_mfa + desc: 'Resumable sign in with SMS MFA flow' + framework: next + category: auth + sample_name: [mfa] + spec: sign-in-resumable-mfa + browser: [chrome] # DISABLED Angular/Vue tests: # TODO: delete tests or add custom ui logic to support them. diff --git a/packages/auth/__tests__/providers/cognito/signInResumable.test.ts b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts new file mode 100644 index 00000000000..65478192b58 --- /dev/null +++ b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts @@ -0,0 +1,268 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +import { Amplify, syncSessionStorage } from '@aws-amplify/core'; + +import { + setActiveSignInState, + signInStore, +} from '../../../src/client/utils/store/signInStore'; +import { cognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider'; +import { + ChallengeName, + RespondToAuthChallengeCommandOutput, +} from '../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/types'; +import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers'; +import { signIn } from '../../../src/providers/cognito'; + +import { setUpGetConfig } from './testUtils/setUpGetConfig'; +import { authAPITestParams } from './testUtils/authApiTestParams'; + +const signInStoreImplementation = require('../../../src/client/utils/store/signInStore'); + +jest.mock('@aws-amplify/core/internals/utils'); +jest.mock('../../../src/providers/cognito/apis/getCurrentUser'); +jest.mock('@aws-amplify/core', () => ({ + ...(jest.createMockFromModule('@aws-amplify/core') as object), + Amplify: { + getConfig: jest.fn(() => ({})), + ADD_OAUTH_LISTENER: jest.fn(() => ({})), + }, + syncSessionStorage: { + setItem: jest.fn((key, value) => { + window.sessionStorage.setItem(key, value); + }), + getItem: jest.fn((key: string) => { + return window.sessionStorage.getItem(key); + }), + removeItem: jest.fn((key: string) => { + window.sessionStorage.removeItem(key); + }), + }, +})); + +const signInStateKeys: Record = { + username: 'CognitoSignInState.username', + challengeName: 'CognitoSignInState.challengeName', + signInSession: 'CognitoSignInState.signInSession', + expiry: 'CognitoSignInState.expiry', +}; + +const user1: Record = { + username: 'joonchoi', + challengeName: 'CUSTOM_CHALLENGE', + signInSession: '888577-ltfgo-42d8-891d-666l858766g7', + expiry: '1234567', +}; + +const populateValidTestSyncStorage = () => { + syncSessionStorage.setItem(signInStateKeys.username, user1.username); + syncSessionStorage.setItem( + signInStateKeys.signInSession, + user1.signInSession, + ); + syncSessionStorage.setItem( + signInStateKeys.challengeName, + user1.challengeName, + ); + syncSessionStorage.setItem( + signInStateKeys.expiry, + (new Date().getTime() + 9999999).toString(), + ); + + signInStore.dispatch({ + type: 'SET_INITIAL_STATE', + }); +}; + +const populateInvalidTestSyncStorage = () => { + syncSessionStorage.setItem(signInStateKeys.username, user1.username); + syncSessionStorage.setItem( + signInStateKeys.signInSession, + user1.signInSession, + ); + syncSessionStorage.setItem( + signInStateKeys.challengeName, + user1.challengeName, + ); + syncSessionStorage.setItem( + signInStateKeys.expiry, + (new Date().getTime() - 99999).toString(), + ); + + signInStore.dispatch({ + type: 'SET_INITIAL_STATE', + }); +}; + +describe('signInStore', () => { + const authConfig = { + Cognito: { + userPoolClientId: '123456-abcde-42d8-891d-666l858766g7', + userPoolId: 'us-west-7_ampjc', + }, + }; + + const session = '1234234232'; + const challengeName = 'SMS_MFA'; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; + + beforeEach(() => { + cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); + }); + + beforeAll(() => { + setUpGetConfig(Amplify); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + afterAll(() => { + jest.restoreAllMocks(); + }); + + test('LocalSignInState is empty after initialization', async () => { + const localSignInState = signInStore.getState(); + + expect(localSignInState).toEqual({ + challengeName: undefined, + signInSession: undefined, + username: undefined, + }); + signInStore.dispatch({ type: 'RESET_STATE' }); + }); + + test('State is set after calling setActiveSignInState', async () => { + const persistSignInStateSpy = jest.spyOn( + signInStoreImplementation, + 'persistSignInState', + ); + setActiveSignInState(user1); + const localSignInState = signInStore.getState(); + + expect(localSignInState).toEqual(user1); + expect(persistSignInStateSpy).toHaveBeenCalledTimes(1); + expect(persistSignInStateSpy).toHaveBeenCalledWith(user1); + signInStore.dispatch({ type: 'RESET_STATE' }); + }); + + test('State is updated after calling SignIn', async () => { + const handleUserSRPAuthflowSpy = jest + .spyOn(signInHelpers, 'handleUserSRPAuthFlow') + .mockImplementationOnce( + async (): Promise => ({ + ChallengeName: challengeName, + Session: session, + $metadata: {}, + ChallengeParameters: { + CODE_DELIVERY_DELIVERY_MEDIUM: 'SMS', + CODE_DELIVERY_DESTINATION: '*******9878', + }, + }), + ); + + await signIn({ + username, + password, + }); + const newLocalSignInState = signInStore.getState(); + + expect(handleUserSRPAuthflowSpy).toHaveBeenCalledTimes(1); + expect(newLocalSignInState).toEqual({ + challengeName, + signInSession: session, + username, + signInDetails: { + loginId: username, + authFlowType: 'USER_SRP_AUTH', + }, + }); + handleUserSRPAuthflowSpy.mockClear(); + }); + + test('The stored sign-in state should be rehydrated if the sign-in session is still valid.', () => { + populateValidTestSyncStorage(); + + const localSignInState = signInStore.getState(); + + expect(localSignInState).toEqual({ + username: user1.username, + challengeName: user1.challengeName, + signInSession: user1.signInSession, + }); + signInStore.dispatch({ type: 'RESET_STATE' }); + }); + + test('sign-in store should return undefined state when the sign-in session is expired', async () => { + populateInvalidTestSyncStorage(); + + const localSignInState = signInStore.getState(); + + expect(localSignInState).toEqual({ + username: undefined, + challengeName: undefined, + signInSession: undefined, + }); + signInStore.dispatch({ type: 'RESET_STATE' }); + }); + + test('State SignInSession is updated after dispatching custom session value', () => { + const persistSignInStateSpy = jest.spyOn( + signInStoreImplementation, + 'persistSignInState', + ); + const newSignInSessionID = '135790-dodge-2468-9aaa-kersh23lad00'; + + populateValidTestSyncStorage(); + + const localSignInState = signInStore.getState(); + expect(localSignInState).toEqual({ + username: user1.username, + challengeName: user1.challengeName, + signInSession: user1.signInSession, + }); + + signInStore.dispatch({ + type: 'SET_SIGN_IN_SESSION', + value: newSignInSessionID, + }); + + expect(persistSignInStateSpy).toHaveBeenCalledTimes(1); + expect(persistSignInStateSpy).toHaveBeenCalledWith({ + signInSession: newSignInSessionID, + }); + const newLocalSignInState = signInStore.getState(); + expect(newLocalSignInState).toEqual({ + username: user1.username, + challengeName: user1.challengeName, + signInSession: newSignInSessionID, + }); + }); + + test('State Challenge Name is updated after dispatching custom challenge name', () => { + const newChallengeName = 'RANDOM_CHALLENGE' as ChallengeName; + + populateValidTestSyncStorage(); + + const localSignInState = signInStore.getState(); + expect(localSignInState).toEqual({ + username: user1.username, + challengeName: user1.challengeName, + signInSession: user1.signInSession, + }); + + signInStore.dispatch({ + type: 'SET_CHALLENGE_NAME', + value: newChallengeName, + }); + + const newLocalSignInState = signInStore.getState(); + expect(newLocalSignInState).toEqual({ + username: user1.username, + challengeName: newChallengeName, + signInSession: user1.signInSession, + }); + }); +}); diff --git a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts index 73e3cdc6eea..bf0735f8f07 100644 --- a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts @@ -5,7 +5,7 @@ import { Amplify } from '@aws-amplify/core'; import { getCurrentUser, signIn } from '../../../src/providers/cognito'; import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers'; -import { signInStore } from '../../../src/client/utils/store'; +import { signInStore } from '../../../src/client/utils/store/signInStore'; import { cognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider'; import { RespondToAuthChallengeCommandOutput } from '../../../src/foundation/factories/serviceClients/cognitoIdentityProvider/types'; @@ -30,6 +30,7 @@ describe('local sign-in state management tests', () => { beforeEach(() => { cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); + signInStore.dispatch({ type: 'RESET_STATE' }); }); test('local state management should return state after signIn returns a ChallengeName', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts index 8f91323319f..486d4fd9a81 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts @@ -42,7 +42,20 @@ jest.mock('@aws-amplify/core', () => { getConfig: jest.fn(() => mockAuthConfigWithOAuth), [ACTUAL_ADD_OAUTH_LISTENER]: jest.fn(), }, - ConsoleLogger: jest.fn(), + ConsoleLogger: jest.fn().mockImplementation(() => { + return { warn: jest.fn() }; + }), + syncSessionStorage: { + setItem: jest.fn((key, value) => { + window.sessionStorage.setItem(key, value); + }), + getItem: jest.fn((key: string) => { + return window.sessionStorage.getItem(key); + }), + removeItem: jest.fn((key: string) => { + window.sessionStorage.removeItem(key); + }), + }, }; }); diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index 94311ce2b74..5680274c5a1 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -1,6 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { syncSessionStorage } from '@aws-amplify/core'; + import { CognitoAuthSignInDetails } from '../../../providers/cognito/types'; import { ChallengeName } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types'; @@ -19,46 +21,113 @@ type SignInAction = | { type: 'SET_SIGN_IN_STATE'; value: SignInState } | { type: 'SET_USERNAME'; value?: string } | { type: 'SET_CHALLENGE_NAME'; value?: ChallengeName } - | { type: 'SET_SIGN_IN_SESSION'; value?: string }; + | { type: 'SET_SIGN_IN_SESSION'; value?: string } + | { type: 'RESET_STATE' }; + +// Minutes until stored session invalidates +const MS_TO_EXPIRY = 3 * 60 * 1000; // 3 mins +const TGT_STATE = 'CognitoSignInState'; +const SIGN_IN_STATE_KEYS = { + username: `${TGT_STATE}.username`, + challengeName: `${TGT_STATE}.challengeName`, + signInSession: `${TGT_STATE}.signInSession`, + expiry: `${TGT_STATE}.expiry`, +}; const signInReducer: Reducer = (state, action) => { switch (action.type) { case 'SET_SIGN_IN_SESSION': + persistSignInState({ signInSession: action.value }); + return { ...state, signInSession: action.value, }; + case 'SET_SIGN_IN_STATE': + persistSignInState(action.value); + return { ...action.value, }; + case 'SET_CHALLENGE_NAME': + persistSignInState({ challengeName: action.value }); + return { ...state, challengeName: action.value, }; + case 'SET_USERNAME': + persistSignInState({ username: action.value }); + return { ...state, username: action.value, }; + case 'SET_INITIAL_STATE': - return defaultState(); + return initializeState(); + + case 'RESET_STATE': + clearPersistedSignInState(); + + return getDefaultState(); + + // this state is never reachable default: return state; } }; -function defaultState(): SignInState { - return { - username: undefined, - challengeName: undefined, - signInSession: undefined, - }; -} +const isExpired = (expiryDate: string | null): boolean => { + const expiryTimestamp = Number(expiryDate); + const currentTimestamp = Date.now(); + + return expiryTimestamp <= currentTimestamp; +}; + +const clearPersistedSignInState = () => { + for (const storedKey of Object.values(SIGN_IN_STATE_KEYS)) { + syncSessionStorage.removeItem(storedKey); + } +}; + +const getDefaultState = (): SignInState => ({ + username: undefined, + challengeName: undefined, + signInSession: undefined, +}); + +// Hydrate signInStore from Synced Session Storage +const initializeState = (): SignInState => { + const expiry = syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.expiry); + + if (!expiry || (expiry && isExpired(expiry))) { + clearPersistedSignInState(); + + return getDefaultState(); + } else { + const username = + syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.username) ?? undefined; + + const challengeName = (syncSessionStorage.getItem( + SIGN_IN_STATE_KEYS.challengeName, + ) ?? undefined) as ChallengeName; + const signInSession = + syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.signInSession) ?? undefined; + + return { + username, + challengeName, + signInSession, + }; + } +}; const createStore: Store = reducer => { - let currentState = reducer(defaultState(), { type: 'SET_INITIAL_STATE' }); + let currentState = reducer(getDefaultState(), { type: 'SET_INITIAL_STATE' }); return { getState: () => currentState, @@ -77,6 +146,23 @@ export function setActiveSignInState(state: SignInState): void { }); } -export function cleanActiveSignInState(): void { - signInStore.dispatch({ type: 'SET_INITIAL_STATE' }); -} +// Save local state into Session Storage +export const persistSignInState = ({ + challengeName, + signInSession, + username, +}: SignInState) => { + username && syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.username, username); + challengeName && + syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.challengeName, challengeName); + + if (signInSession) { + syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.signInSession, signInSession); + + // Updates expiry when session is passed + syncSessionStorage.setItem( + SIGN_IN_STATE_KEYS.expiry, + String(Date.now() + MS_TO_EXPIRY), + ); + } +}; diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ae62578be5e..e3b475ad6dc 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -11,10 +11,9 @@ import { } from '../types/errors'; import { ConfirmSignInInput, ConfirmSignInOutput } from '../types'; import { - cleanActiveSignInState, setActiveSignInState, signInStore, -} from '../../../client/utils/store'; +} from '../../../client/utils/store/signInStore'; import { AuthError } from '../../../errors/AuthError'; import { getNewDeviceMetadata, @@ -120,7 +119,7 @@ export async function confirmSignIn( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 5911266475b..aeac80eaa25 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -22,9 +22,9 @@ import { SignInWithCustomAuthOutput, } from '../types'; import { - cleanActiveSignInState, setActiveSignInState, -} from '../../../client/utils/store'; + signInStore, +} from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { ChallengeName, @@ -95,7 +95,7 @@ export async function signInWithCustomAuth( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); @@ -110,7 +110,7 @@ export async function signInWithCustomAuth( challengeParameters: retiredChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts index 4966cfaa9fa..37d65122b41 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts @@ -24,9 +24,9 @@ import { SignInWithCustomSRPAuthOutput, } from '../types'; import { - cleanActiveSignInState, setActiveSignInState, -} from '../../../client/utils/store'; + signInStore, +} from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { ChallengeName, @@ -100,7 +100,7 @@ export async function signInWithCustomSRPAuth( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); @@ -115,7 +115,7 @@ export async function signInWithCustomSRPAuth( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index aa92e3e6012..8290c1403cd 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -28,9 +28,9 @@ import { SignInWithSRPOutput, } from '../types'; import { - cleanActiveSignInState, setActiveSignInState, -} from '../../../client/utils/store'; + signInStore, +} from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { tokenOrchestrator } from '../tokenProvider'; import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent'; @@ -102,7 +102,7 @@ export async function signInWithSRP( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); @@ -119,8 +119,7 @@ export async function signInWithSRP( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); - resetAutoSignIn(); + signInStore.dispatch({ type: 'RESET_STATE' }); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 8027af90c71..3889c74be5c 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -26,9 +26,9 @@ import { SignInWithUserPasswordOutput, } from '../types'; import { - cleanActiveSignInState, setActiveSignInState, -} from '../../../client/utils/store'; + signInStore, +} from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { tokenOrchestrator } from '../tokenProvider'; import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent'; @@ -97,7 +97,7 @@ export async function signInWithUserPassword( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); @@ -114,8 +114,7 @@ export async function signInWithUserPassword( challengeParameters: retriedChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); - resetAutoSignIn(); + signInStore.dispatch({ type: 'RESET_STATE' }); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index d37e20ef483..4b57816fdcd 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -383,7 +383,7 @@ "name": "[Auth] confirmSignIn (Cognito)", "path": "./dist/esm/auth/index.mjs", "import": "{ confirmSignIn }", - "limit": "28.46 kB" + "limit": "28.60 kB" }, { "name": "[Auth] updateMFAPreference (Cognito)", @@ -449,7 +449,7 @@ "name": "[Auth] Basic Auth Flow (Cognito)", "path": "./dist/esm/auth/index.mjs", "import": "{ signIn, signOut, fetchAuthSession, confirmSignIn }", - "limit": "30.56 kB" + "limit": "30.45 kB" }, { "name": "[Auth] OAuth Auth Flow (Cognito)", @@ -515,7 +515,7 @@ "name": "[Storage] uploadData (S3)", "path": "./dist/esm/storage/index.mjs", "import": "{ uploadData }", - "limit": "22.81 kB" + "limit": "19.99 kB" } ] } diff --git a/packages/core/__tests__/storage/SyncSessionStorage.test.ts b/packages/core/__tests__/storage/SyncSessionStorage.test.ts new file mode 100644 index 00000000000..5b27081891b --- /dev/null +++ b/packages/core/__tests__/storage/SyncSessionStorage.test.ts @@ -0,0 +1,80 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +import { SyncSessionStorage } from '../../src/storage/SyncSessionStorage'; + +describe('SyncSessionStorage', () => { + let sessionStorage: SyncSessionStorage; + const signInStateKeys: Record = { + username: 'CognitoSignInState.username', + challengeName: 'CognitoSignInState.challengeName', + signInSession: 'CognitoSignInState.signInSession', + expiry: 'CognitoSignInState.expiry', + }; + + const user1 = { + username: 'joonchoi', + challengeName: 'CUSTOM_CHALLENGE', + signInSession: '888577-ltfgo-42d8-891d-666l858766g7', + expiry: '1234567', + }; + + beforeEach(() => { + sessionStorage = new SyncSessionStorage(); + }); + + it('can set and retrieve item by key', () => { + sessionStorage.setItem(signInStateKeys.username, user1.username); + sessionStorage.setItem(signInStateKeys.challengeName, user1.challengeName); + sessionStorage.setItem(signInStateKeys.signInSession, user1.signInSession); + sessionStorage.setItem(signInStateKeys.expiry, user1.expiry); + + expect(sessionStorage.getItem(signInStateKeys.username)).toBe( + user1.username, + ); + expect(sessionStorage.getItem(signInStateKeys.challengeName)).toBe( + user1.challengeName, + ); + expect(sessionStorage.getItem(signInStateKeys.signInSession)).toBe( + user1.signInSession, + ); + expect(sessionStorage.getItem(signInStateKeys.expiry)).toBe(user1.expiry); + }); + + it('can override item by setting with the same key', () => { + const newUserName = 'joonchoi+test'; + sessionStorage.setItem(signInStateKeys.username, user1.username); + sessionStorage.setItem(signInStateKeys.username, newUserName); + + expect(sessionStorage.getItem(signInStateKeys.username)).toBe(newUserName); + }); + + it('can remove item by key', () => { + const newUserName = 'joonchoi+tobedeleted'; + sessionStorage.setItem(signInStateKeys.username, newUserName); + expect(sessionStorage.getItem(signInStateKeys.username)).toBe(newUserName); + sessionStorage.removeItem(signInStateKeys.username); + expect(sessionStorage.getItem(signInStateKeys.username)).toBeNull(); + }); + + it('clears all items', () => { + sessionStorage.setItem(signInStateKeys.username, user1.username); + sessionStorage.setItem(signInStateKeys.challengeName, user1.challengeName); + sessionStorage.setItem(signInStateKeys.signInSession, user1.signInSession); + sessionStorage.setItem(signInStateKeys.expiry, user1.expiry); + + sessionStorage.clear(); + + expect(sessionStorage.getItem(signInStateKeys.username)).toBeNull(); + expect(sessionStorage.getItem(signInStateKeys.challengeName)).toBeNull(); + expect(sessionStorage.getItem(signInStateKeys.signInSession)).toBeNull(); + expect(sessionStorage.getItem(signInStateKeys.expiry)).toBeNull(); + }); + + it('will not throw if trying to delete a non existing key', () => { + const badKey = 'nonExistingKey'; + + expect(() => { + sessionStorage.removeItem(badKey); + }).not.toThrow(); + }); +}); diff --git a/packages/core/__tests__/storage/storage-mechanisms-node-runtime.test.ts b/packages/core/__tests__/storage/storage-mechanisms-node-runtime.test.ts deleted file mode 100644 index 0566237962b..00000000000 --- a/packages/core/__tests__/storage/storage-mechanisms-node-runtime.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @jest-environment node - */ - -import { AmplifyError, AmplifyErrorCode } from '../../src/libraryUtils'; -import { defaultStorage, sessionStorage } from '../../src/storage'; - -const key = 'k'; -const value = 'value'; - -describe('test mechanisms', () => { - test('test defaultStorage operations in node environment', async () => { - try { - await defaultStorage.setItem(key, value); - } catch (error: any) { - expect(error).toBeInstanceOf(AmplifyError); - expect(error.name).toBe(AmplifyErrorCode.PlatformNotSupported); - } - }); - - test('test sessionStorage operations in node environment', async () => { - try { - await sessionStorage.setItem(key, value); - } catch (error: any) { - expect(error).toBeInstanceOf(AmplifyError); - expect(error.name).toBe(AmplifyErrorCode.PlatformNotSupported); - } - }); -}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index f17968928c6..2ead3026682 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -59,6 +59,7 @@ export { CookieStorage, defaultStorage, sessionStorage, + syncSessionStorage, sharedInMemoryStorage, } from './storage'; export { KeyValueStorageInterface } from './types'; diff --git a/packages/core/src/storage/SyncKeyValueStorage.ts b/packages/core/src/storage/SyncKeyValueStorage.ts new file mode 100644 index 00000000000..33885f2af31 --- /dev/null +++ b/packages/core/src/storage/SyncKeyValueStorage.ts @@ -0,0 +1,59 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { PlatformNotSupportedError } from '../errors'; +import { SyncStorage } from '../types'; + +/** + * @internal + */ +export class SyncKeyValueStorage implements SyncStorage { + _storage?: Storage; + + constructor(storage?: Storage) { + this._storage = storage; + } + + get storage() { + if (!this._storage) throw new PlatformNotSupportedError(); + + return this._storage; + } + + /** + * This is used to set a specific item in storage + * @param {string} key - the key for the item + * @param {object} value - the value + * @returns {string} value that was set + */ + setItem(key: string, value: string) { + this.storage.setItem(key, value); + } + + /** + * This is used to get a specific key from storage + * @param {string} key - the key for the item + * This is used to clear the storage + * @returns {string} the data item + */ + getItem(key: string) { + return this.storage.getItem(key); + } + + /** + * This is used to remove an item from storage + * @param {string} key - the key being set + * @returns {string} value - value that was deleted + */ + removeItem(key: string) { + this.storage.removeItem(key); + } + + /** + * This is used to clear the storage + * @returns {string} nothing + */ + clear() { + this.storage.clear(); + } +} diff --git a/packages/core/src/storage/SyncSessionStorage.ts b/packages/core/src/storage/SyncSessionStorage.ts new file mode 100644 index 00000000000..83224bfc878 --- /dev/null +++ b/packages/core/src/storage/SyncSessionStorage.ts @@ -0,0 +1,14 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { SyncKeyValueStorage } from './SyncKeyValueStorage'; +import { getSessionStorageWithFallback } from './utils'; + +/** + * @internal + */ +export class SyncSessionStorage extends SyncKeyValueStorage { + constructor() { + super(getSessionStorageWithFallback()); + } +} diff --git a/packages/core/src/storage/index.ts b/packages/core/src/storage/index.ts index 29fba0b3dea..72219167521 100644 --- a/packages/core/src/storage/index.ts +++ b/packages/core/src/storage/index.ts @@ -5,9 +5,11 @@ import { DefaultStorage } from './DefaultStorage'; import { InMemoryStorage } from './InMemoryStorage'; import { KeyValueStorage } from './KeyValueStorage'; import { SessionStorage } from './SessionStorage'; +import { SyncSessionStorage } from './SyncSessionStorage'; export { CookieStorage } from './CookieStorage'; export const defaultStorage = new DefaultStorage(); export const sessionStorage = new SessionStorage(); +export const syncSessionStorage = new SyncSessionStorage(); export const sharedInMemoryStorage = new KeyValueStorage(new InMemoryStorage()); diff --git a/packages/core/src/types/storage.ts b/packages/core/src/types/storage.ts index d664a95b446..79a0c63e74b 100644 --- a/packages/core/src/types/storage.ts +++ b/packages/core/src/types/storage.ts @@ -21,3 +21,10 @@ export interface CookieStorageData { secure?: boolean; sameSite?: SameSite; } + +export interface SyncStorage { + setItem(key: string, value: string): void; + getItem(key: string): string | null; + removeItem(key: string): void; + clear(): void; +} From 79b179cb51abed3cac607ae9a3deeb6149223d9a Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:06:23 -0800 Subject: [PATCH 02/13] Replace cleanActiveSignInState --- .../client/flows/userAuth/handleWebAuthnSignInResult.ts | 8 ++------ .../auth/src/providers/cognito/apis/signInWithUserAuth.ts | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/auth/src/client/flows/userAuth/handleWebAuthnSignInResult.ts b/packages/auth/src/client/flows/userAuth/handleWebAuthnSignInResult.ts index 2e67a52a5ab..ee3bc6e6b6c 100644 --- a/packages/auth/src/client/flows/userAuth/handleWebAuthnSignInResult.ts +++ b/packages/auth/src/client/flows/userAuth/handleWebAuthnSignInResult.ts @@ -21,11 +21,7 @@ import { getNewDeviceMetadata, getSignInResult, } from '../../../providers/cognito/utils/signInHelpers'; -import { - cleanActiveSignInState, - setActiveSignInState, - signInStore, -} from '../../../client/utils/store'; +import { setActiveSignInState, signInStore } from '../../../client/utils/store'; import { AuthSignInOutput } from '../../../types'; import { getAuthUserAgentValue } from '../../../utils'; import { getPasskey } from '../../utils/passkey'; @@ -106,7 +102,7 @@ export async function handleWebAuthnSignInResult( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 94165046864..77caf188ee7 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -28,8 +28,8 @@ import { } from '../types'; import { autoSignInStore, - cleanActiveSignInState, setActiveSignInState, + signInStore, } from '../../../client/utils/store'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent'; @@ -111,7 +111,7 @@ export async function signInWithUserAuth( }), signInDetails, }); - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); await dispatchSignedInHubEvent(); @@ -132,7 +132,7 @@ export async function signInWithUserAuth( : undefined, }); } catch (error) { - cleanActiveSignInState(); + signInStore.dispatch({ type: 'RESET_STATE' }); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); From 2dec0770239573ede9accc686f6a065052c46a41 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:16:32 -0800 Subject: [PATCH 03/13] Increase bundle size --- packages/aws-amplify/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index 4b57816fdcd..d00bf8e2379 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -449,7 +449,7 @@ "name": "[Auth] Basic Auth Flow (Cognito)", "path": "./dist/esm/auth/index.mjs", "import": "{ signIn, signOut, fetchAuthSession, confirmSignIn }", - "limit": "30.45 kB" + "limit": "30.87 kB" }, { "name": "[Auth] OAuth Auth Flow (Cognito)", @@ -515,7 +515,7 @@ "name": "[Storage] uploadData (S3)", "path": "./dist/esm/storage/index.mjs", "import": "{ uploadData }", - "limit": "19.99 kB" + "limit": "22.84 kB" } ] } From fee0ada9a4ee6f663b6e483bc2cd5ee256ebb102 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:18:40 -0800 Subject: [PATCH 04/13] Update mock target --- .../__tests__/providers/cognito/confirmSignInErrorCases.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts index ce786ece3cb..44fdf58436f 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts @@ -16,7 +16,7 @@ jest.mock('@aws-amplify/core', () => ({ ...(jest.createMockFromModule('@aws-amplify/core') as object), Amplify: { getConfig: jest.fn(() => ({})) }, })); -jest.mock('../../../src/client/utils/store'); +jest.mock('../../../src/client/utils/store/signInStore'); jest.mock( '../../../src/foundation/factories/serviceClients/cognitoIdentityProvider', ); From 17d4448a196f847b13a2dd98ac83a9be0c954a54 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:50:54 -0800 Subject: [PATCH 05/13] Restore resetAutoSignIn --- packages/auth/src/providers/cognito/apis/signInWithSRP.ts | 1 + .../auth/src/providers/cognito/apis/signInWithUserPassword.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 8290c1403cd..2c5fddb0499 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -120,6 +120,7 @@ export async function signInWithSRP( }); } catch (error) { signInStore.dispatch({ type: 'RESET_STATE' }); + resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 3889c74be5c..3cad67bd711 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -115,6 +115,7 @@ export async function signInWithUserPassword( }); } catch (error) { signInStore.dispatch({ type: 'RESET_STATE' }); + resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; From 8303ded58924886598e52077a1f0e790959f155b Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:21:16 -0800 Subject: [PATCH 06/13] Match mock import directory --- .../providers/cognito/confirmSignInErrorCases.test.ts | 2 +- packages/auth/src/providers/cognito/apis/confirmSignIn.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts index 44fdf58436f..ce786ece3cb 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts @@ -16,7 +16,7 @@ jest.mock('@aws-amplify/core', () => ({ ...(jest.createMockFromModule('@aws-amplify/core') as object), Amplify: { getConfig: jest.fn(() => ({})) }, })); -jest.mock('../../../src/client/utils/store/signInStore'); +jest.mock('../../../src/client/utils/store'); jest.mock( '../../../src/foundation/factories/serviceClients/cognitoIdentityProvider', ); diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index e3b475ad6dc..2c8b4e576d8 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -10,10 +10,7 @@ import { VerifySoftwareTokenException, } from '../types/errors'; import { ConfirmSignInInput, ConfirmSignInOutput } from '../types'; -import { - setActiveSignInState, - signInStore, -} from '../../../client/utils/store/signInStore'; +import { setActiveSignInState, signInStore } from '../../../client/utils/store'; import { AuthError } from '../../../errors/AuthError'; import { getNewDeviceMetadata, From 0145caa4b2c08cb07f86cad1b6b0e1f1f7297233 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:56:22 -0800 Subject: [PATCH 07/13] Enable Firefox testing on SMS MFA flow with Resumable Sign In --- .github/integ-config/integ-all.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 34736a01399..047a7385eb7 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -622,7 +622,7 @@ tests: category: auth sample_name: [mfa] spec: sign-in-resumable-mfa - browser: [chrome] + browser: *minimal_browser_list # DISABLED Angular/Vue tests: # TODO: delete tests or add custom ui logic to support them. From 521a99485ceddbd12422cbf83d86a972bb7e5c3c Mon Sep 17 00:00:00 2001 From: Joon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:14:05 -0800 Subject: [PATCH 08/13] Update packages/auth/src/client/utils/store/signInStore.ts Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com> --- packages/auth/src/client/utils/store/signInStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index 5680274c5a1..39f1b3557b0 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -89,7 +89,7 @@ const isExpired = (expiryDate: string | null): boolean => { }; const clearPersistedSignInState = () => { - for (const storedKey of Object.values(SIGN_IN_STATE_KEYS)) { + for (const stateKey of Object.values(SIGN_IN_STATE_KEYS)) { syncSessionStorage.removeItem(storedKey); } }; From d0391fb3047ecb2cf9dcb5e601ceeb97a2396832 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:45:23 -0800 Subject: [PATCH 09/13] Address the comments --- .../auth/src/client/utils/store/signInStore.ts | 8 ++++---- .../storage/SyncSessionStorage.test.ts | 17 +++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index 39f1b3557b0..76f1468ebed 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -68,7 +68,7 @@ const signInReducer: Reducer = (state, action) => { }; case 'SET_INITIAL_STATE': - return initializeState(); + return getInitialState(); case 'RESET_STATE': clearPersistedSignInState(); @@ -90,7 +90,7 @@ const isExpired = (expiryDate: string | null): boolean => { const clearPersistedSignInState = () => { for (const stateKey of Object.values(SIGN_IN_STATE_KEYS)) { - syncSessionStorage.removeItem(storedKey); + syncSessionStorage.removeItem(stateKey); } }; @@ -100,8 +100,8 @@ const getDefaultState = (): SignInState => ({ signInSession: undefined, }); -// Hydrate signInStore from Synced Session Storage -const initializeState = (): SignInState => { +// Hydrate signInStore from syncSessionStorage +const getInitialState = (): SignInState => { const expiry = syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.expiry); if (!expiry || (expiry && isExpired(expiry))) { diff --git a/packages/core/__tests__/storage/SyncSessionStorage.test.ts b/packages/core/__tests__/storage/SyncSessionStorage.test.ts index 5b27081891b..fb56565d598 100644 --- a/packages/core/__tests__/storage/SyncSessionStorage.test.ts +++ b/packages/core/__tests__/storage/SyncSessionStorage.test.ts @@ -24,25 +24,18 @@ describe('SyncSessionStorage', () => { it('can set and retrieve item by key', () => { sessionStorage.setItem(signInStateKeys.username, user1.username); - sessionStorage.setItem(signInStateKeys.challengeName, user1.challengeName); - sessionStorage.setItem(signInStateKeys.signInSession, user1.signInSession); - sessionStorage.setItem(signInStateKeys.expiry, user1.expiry); expect(sessionStorage.getItem(signInStateKeys.username)).toBe( user1.username, ); - expect(sessionStorage.getItem(signInStateKeys.challengeName)).toBe( - user1.challengeName, - ); - expect(sessionStorage.getItem(signInStateKeys.signInSession)).toBe( - user1.signInSession, - ); - expect(sessionStorage.getItem(signInStateKeys.expiry)).toBe(user1.expiry); }); it('can override item by setting with the same key', () => { const newUserName = 'joonchoi+test'; sessionStorage.setItem(signInStateKeys.username, user1.username); + expect(sessionStorage.getItem(signInStateKeys.username)).toBe( + user1.username, + ); sessionStorage.setItem(signInStateKeys.username, newUserName); expect(sessionStorage.getItem(signInStateKeys.username)).toBe(newUserName); @@ -58,16 +51,12 @@ describe('SyncSessionStorage', () => { it('clears all items', () => { sessionStorage.setItem(signInStateKeys.username, user1.username); - sessionStorage.setItem(signInStateKeys.challengeName, user1.challengeName); sessionStorage.setItem(signInStateKeys.signInSession, user1.signInSession); - sessionStorage.setItem(signInStateKeys.expiry, user1.expiry); sessionStorage.clear(); expect(sessionStorage.getItem(signInStateKeys.username)).toBeNull(); - expect(sessionStorage.getItem(signInStateKeys.challengeName)).toBeNull(); expect(sessionStorage.getItem(signInStateKeys.signInSession)).toBeNull(); - expect(sessionStorage.getItem(signInStateKeys.expiry)).toBeNull(); }); it('will not throw if trying to delete a non existing key', () => { From b6f7383f4289042f846a01becde31effaec90169 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:00:28 -0800 Subject: [PATCH 10/13] Address the comments --- .../src/client/utils/store/signInStore.ts | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index 76f1468ebed..d46d4e3f46d 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -108,22 +108,21 @@ const getInitialState = (): SignInState => { clearPersistedSignInState(); return getDefaultState(); - } else { - const username = - syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.username) ?? undefined; - - const challengeName = (syncSessionStorage.getItem( - SIGN_IN_STATE_KEYS.challengeName, - ) ?? undefined) as ChallengeName; - const signInSession = - syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.signInSession) ?? undefined; - - return { - username, - challengeName, - signInSession, - }; } + const username = + syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.username) ?? undefined; + + const challengeName = (syncSessionStorage.getItem( + SIGN_IN_STATE_KEYS.challengeName, + ) ?? undefined) as ChallengeName; + const signInSession = + syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.signInSession) ?? undefined; + + return { + username, + challengeName, + signInSession, + }; }; const createStore: Store = reducer => { From 220abee63f6e2fe37e41f08e7c8e1446c93dab47 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:17:35 -0800 Subject: [PATCH 11/13] Recreate cleanActiveSignInStore --- .../__tests__/providers/cognito/signInResumable.test.ts | 9 +++++---- packages/auth/src/client/utils/store/signInStore.ts | 4 ++++ .../auth/src/providers/cognito/apis/confirmSignIn.ts | 8 ++++++-- .../src/providers/cognito/apis/signInWithCustomAuth.ts | 6 +++--- .../providers/cognito/apis/signInWithCustomSRPAuth.ts | 6 +++--- .../auth/src/providers/cognito/apis/signInWithSRP.ts | 6 +++--- .../src/providers/cognito/apis/signInWithUserAuth.ts | 6 +++--- .../src/providers/cognito/apis/signInWithUserPassword.ts | 6 +++--- 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/packages/auth/__tests__/providers/cognito/signInResumable.test.ts b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts index 65478192b58..f3e61546d49 100644 --- a/packages/auth/__tests__/providers/cognito/signInResumable.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts @@ -3,6 +3,7 @@ import { Amplify, syncSessionStorage } from '@aws-amplify/core'; import { + cleanActiveSignInState, setActiveSignInState, signInStore, } from '../../../src/client/utils/store/signInStore'; @@ -131,7 +132,7 @@ describe('signInStore', () => { signInSession: undefined, username: undefined, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); }); test('State is set after calling setActiveSignInState', async () => { @@ -145,7 +146,7 @@ describe('signInStore', () => { expect(localSignInState).toEqual(user1); expect(persistSignInStateSpy).toHaveBeenCalledTimes(1); expect(persistSignInStateSpy).toHaveBeenCalledWith(user1); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); }); test('State is updated after calling SignIn', async () => { @@ -192,7 +193,7 @@ describe('signInStore', () => { challengeName: user1.challengeName, signInSession: user1.signInSession, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); }); test('sign-in store should return undefined state when the sign-in session is expired', async () => { @@ -205,7 +206,7 @@ describe('signInStore', () => { challengeName: undefined, signInSession: undefined, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); }); test('State SignInSession is updated after dispatching custom session value', () => { diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index d46d4e3f46d..827bf43a2b5 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -88,6 +88,10 @@ const isExpired = (expiryDate: string | null): boolean => { return expiryTimestamp <= currentTimestamp; }; +export const cleanActiveSignInState = () => { + signInStore.dispatch({ type: 'RESET_STATE' }); +}; + const clearPersistedSignInState = () => { for (const stateKey of Object.values(SIGN_IN_STATE_KEYS)) { syncSessionStorage.removeItem(stateKey); diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index 2c8b4e576d8..ae62578be5e 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -10,7 +10,11 @@ import { VerifySoftwareTokenException, } from '../types/errors'; import { ConfirmSignInInput, ConfirmSignInOutput } from '../types'; -import { setActiveSignInState, signInStore } from '../../../client/utils/store'; +import { + cleanActiveSignInState, + setActiveSignInState, + signInStore, +} from '../../../client/utils/store'; import { AuthError } from '../../../errors/AuthError'; import { getNewDeviceMetadata, @@ -116,7 +120,7 @@ export async function confirmSignIn( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index aeac80eaa25..670febff30f 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -22,8 +22,8 @@ import { SignInWithCustomAuthOutput, } from '../types'; import { + cleanActiveSignInState, setActiveSignInState, - signInStore, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { @@ -95,7 +95,7 @@ export async function signInWithCustomAuth( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); @@ -110,7 +110,7 @@ export async function signInWithCustomAuth( challengeParameters: retiredChallengeParameters as ChallengeParameters, }); } catch (error) { - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts index 37d65122b41..8730a52a1cd 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts @@ -24,8 +24,8 @@ import { SignInWithCustomSRPAuthOutput, } from '../types'; import { + cleanActiveSignInState, setActiveSignInState, - signInStore, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { @@ -100,7 +100,7 @@ export async function signInWithCustomSRPAuth( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); @@ -115,7 +115,7 @@ export async function signInWithCustomSRPAuth( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 2c5fddb0499..52abfd978a7 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -28,8 +28,8 @@ import { SignInWithSRPOutput, } from '../types'; import { + cleanActiveSignInState, setActiveSignInState, - signInStore, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { tokenOrchestrator } from '../tokenProvider'; @@ -102,7 +102,7 @@ export async function signInWithSRP( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); @@ -119,7 +119,7 @@ export async function signInWithSRP( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 77caf188ee7..94165046864 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -28,8 +28,8 @@ import { } from '../types'; import { autoSignInStore, + cleanActiveSignInState, setActiveSignInState, - signInStore, } from '../../../client/utils/store'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent'; @@ -111,7 +111,7 @@ export async function signInWithUserAuth( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); @@ -132,7 +132,7 @@ export async function signInWithUserAuth( : undefined, }); } catch (error) { - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 3cad67bd711..ee616b6b4a6 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -26,8 +26,8 @@ import { SignInWithUserPasswordOutput, } from '../types'; import { + cleanActiveSignInState, setActiveSignInState, - signInStore, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { tokenOrchestrator } from '../tokenProvider'; @@ -97,7 +97,7 @@ export async function signInWithUserPassword( }), signInDetails, }); - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); @@ -114,7 +114,7 @@ export async function signInWithUserPassword( challengeParameters: retriedChallengeParameters as ChallengeParameters, }); } catch (error) { - signInStore.dispatch({ type: 'RESET_STATE' }); + cleanActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); From bfdbae87b94c75173de5fa7fa4e55efce6a984ba Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:36:51 -0800 Subject: [PATCH 12/13] Introduce resetActiveSignInState --- .../providers/cognito/signInResumable.test.ts | 10 +++++----- packages/auth/src/client/utils/store/signInStore.ts | 4 ++-- .../auth/src/providers/cognito/apis/confirmSignIn.ts | 4 ++-- .../src/providers/cognito/apis/signInWithCustomAuth.ts | 6 +++--- .../providers/cognito/apis/signInWithCustomSRPAuth.ts | 6 +++--- .../auth/src/providers/cognito/apis/signInWithSRP.ts | 6 +++--- .../src/providers/cognito/apis/signInWithUserAuth.ts | 6 +++--- .../providers/cognito/apis/signInWithUserPassword.ts | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/auth/__tests__/providers/cognito/signInResumable.test.ts b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts index f3e61546d49..7bc3a8d324a 100644 --- a/packages/auth/__tests__/providers/cognito/signInResumable.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInResumable.test.ts @@ -3,7 +3,7 @@ import { Amplify, syncSessionStorage } from '@aws-amplify/core'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, signInStore, } from '../../../src/client/utils/store/signInStore'; @@ -132,7 +132,7 @@ describe('signInStore', () => { signInSession: undefined, username: undefined, }); - cleanActiveSignInState(); + resetActiveSignInState(); }); test('State is set after calling setActiveSignInState', async () => { @@ -146,7 +146,7 @@ describe('signInStore', () => { expect(localSignInState).toEqual(user1); expect(persistSignInStateSpy).toHaveBeenCalledTimes(1); expect(persistSignInStateSpy).toHaveBeenCalledWith(user1); - cleanActiveSignInState(); + resetActiveSignInState(); }); test('State is updated after calling SignIn', async () => { @@ -193,7 +193,7 @@ describe('signInStore', () => { challengeName: user1.challengeName, signInSession: user1.signInSession, }); - cleanActiveSignInState(); + resetActiveSignInState(); }); test('sign-in store should return undefined state when the sign-in session is expired', async () => { @@ -206,7 +206,7 @@ describe('signInStore', () => { challengeName: undefined, signInSession: undefined, }); - cleanActiveSignInState(); + resetActiveSignInState(); }); test('State SignInSession is updated after dispatching custom session value', () => { diff --git a/packages/auth/src/client/utils/store/signInStore.ts b/packages/auth/src/client/utils/store/signInStore.ts index 827bf43a2b5..80b27f2a1c2 100644 --- a/packages/auth/src/client/utils/store/signInStore.ts +++ b/packages/auth/src/client/utils/store/signInStore.ts @@ -88,7 +88,7 @@ const isExpired = (expiryDate: string | null): boolean => { return expiryTimestamp <= currentTimestamp; }; -export const cleanActiveSignInState = () => { +export const resetActiveSignInState = () => { signInStore.dispatch({ type: 'RESET_STATE' }); }; @@ -108,7 +108,7 @@ const getDefaultState = (): SignInState => ({ const getInitialState = (): SignInState => { const expiry = syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.expiry); - if (!expiry || (expiry && isExpired(expiry))) { + if (!expiry || isExpired(expiry)) { clearPersistedSignInState(); return getDefaultState(); diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ae62578be5e..9a9af8e75b5 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -11,7 +11,7 @@ import { } from '../types/errors'; import { ConfirmSignInInput, ConfirmSignInOutput } from '../types'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, signInStore, } from '../../../client/utils/store'; @@ -120,7 +120,7 @@ export async function confirmSignIn( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 670febff30f..3ee2de1302c 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -22,7 +22,7 @@ import { SignInWithCustomAuthOutput, } from '../types'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; @@ -95,7 +95,7 @@ export async function signInWithCustomAuth( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); @@ -110,7 +110,7 @@ export async function signInWithCustomAuth( challengeParameters: retiredChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + resetActiveSignInState(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts index 8730a52a1cd..35eb7f29419 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomSRPAuth.ts @@ -24,7 +24,7 @@ import { SignInWithCustomSRPAuthOutput, } from '../types'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; @@ -100,7 +100,7 @@ export async function signInWithCustomSRPAuth( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); @@ -115,7 +115,7 @@ export async function signInWithCustomSRPAuth( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + resetActiveSignInState(); assertServiceError(error); const result = getSignInResultFromError(error.name); if (result) return result; diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 52abfd978a7..05c79cf35a0 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -28,7 +28,7 @@ import { SignInWithSRPOutput, } from '../types'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; @@ -102,7 +102,7 @@ export async function signInWithSRP( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); @@ -119,7 +119,7 @@ export async function signInWithSRP( challengeParameters: handledChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + resetActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 94165046864..37772c559cd 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -28,7 +28,7 @@ import { } from '../types'; import { autoSignInStore, - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; @@ -111,7 +111,7 @@ export async function signInWithUserAuth( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); @@ -132,7 +132,7 @@ export async function signInWithUserAuth( : undefined, }); } catch (error) { - cleanActiveSignInState(); + resetActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index ee616b6b4a6..56e1c1af9f5 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -26,7 +26,7 @@ import { SignInWithUserPasswordOutput, } from '../types'; import { - cleanActiveSignInState, + resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; @@ -97,7 +97,7 @@ export async function signInWithUserPassword( }), signInDetails, }); - cleanActiveSignInState(); + resetActiveSignInState(); await dispatchSignedInHubEvent(); @@ -114,7 +114,7 @@ export async function signInWithUserPassword( challengeParameters: retriedChallengeParameters as ChallengeParameters, }); } catch (error) { - cleanActiveSignInState(); + resetActiveSignInState(); resetAutoSignIn(); assertServiceError(error); const result = getSignInResultFromError(error.name); From 67c22aaa0b3fabb7ce95ba2c3dbaffe9c0c0edd4 Mon Sep 17 00:00:00 2001 From: JoonWon Choi <13882232+joon-won@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:35:00 -0800 Subject: [PATCH 13/13] Improve consistency on import path --- .../auth/src/providers/cognito/apis/signInWithUserAuth.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 37772c559cd..4f653f46c94 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -26,11 +26,11 @@ import { SignInWithUserAuthInput, SignInWithUserAuthOutput, } from '../types'; +import { autoSignInStore } from '../../../client/utils/store'; import { - autoSignInStore, resetActiveSignInState, setActiveSignInState, -} from '../../../client/utils/store'; +} from '../../../client/utils/store/signInStore'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent'; import { tokenOrchestrator } from '../tokenProvider';