@aws-amplify/auth 6.8.4-unstable.ec2ff53.0 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js +1 -1
- package/dist/cjs/client/flows/userAuth/handleWebAuthnSignInResult.js.map +1 -1
- package/dist/cjs/client/utils/store/signInStore.js +66 -12
- package/dist/cjs/client/utils/store/signInStore.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js +1 -1
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js +4 -4
- package/dist/cjs/providers/cognito/apis/signInWithCustomAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js +4 -4
- package/dist/cjs/providers/cognito/apis/signInWithCustomSRPAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithSRP.js +4 -4
- package/dist/cjs/providers/cognito/apis/signInWithSRP.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js +4 -3
- package/dist/cjs/providers/cognito/apis/signInWithUserAuth.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js +4 -4
- package/dist/cjs/providers/cognito/apis/signInWithUserPassword.js.map +1 -1
- package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs +2 -2
- package/dist/esm/client/flows/userAuth/handleWebAuthnSignInResult.mjs.map +1 -1
- package/dist/esm/client/utils/store/index.mjs +1 -1
- package/dist/esm/client/utils/store/signInStore.d.ts +4 -1
- package/dist/esm/client/utils/store/signInStore.mjs +65 -11
- package/dist/esm/client/utils/store/signInStore.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -2
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs +3 -4
- package/dist/esm/providers/cognito/apis/signInWithCustomAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs +3 -4
- package/dist/esm/providers/cognito/apis/signInWithCustomSRPAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithSRP.mjs +3 -4
- package/dist/esm/providers/cognito/apis/signInWithSRP.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs +3 -3
- package/dist/esm/providers/cognito/apis/signInWithUserAuth.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs +3 -4
- package/dist/esm/providers/cognito/apis/signInWithUserPassword.mjs.map +1 -1
- package/package.json +104 -104
- package/src/client/flows/userAuth/handleWebAuthnSignInResult.ts +2 -6
- package/src/client/utils/store/signInStore.ts +100 -11
- package/src/providers/cognito/apis/confirmSignIn.ts +2 -2
- package/src/providers/cognito/apis/signInWithCustomAuth.ts +4 -4
- package/src/providers/cognito/apis/signInWithCustomSRPAuth.ts +4 -4
- package/src/providers/cognito/apis/signInWithSRP.ts +4 -4
- package/src/providers/cognito/apis/signInWithUserAuth.ts +5 -5
- package/src/providers/cognito/apis/signInWithUserPassword.ts +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInWithUserPassword.mjs","sources":["../../../../../src/providers/cognito/apis/signInWithUserPassword.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { assertTokenProviderConfig } from '@aws-amplify/core/internals/utils';\nimport { AuthValidationErrorCode } from '../../../errors/types/validation';\nimport { assertServiceError } from '../../../errors/utils/assertServiceError';\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { getActiveSignInUsername, getNewDeviceMetadata, getSignInResult, getSignInResultFromError, handleUserPasswordAuthFlow, retryOnResourceNotFoundException, } from '../utils/signInHelpers';\nimport {
|
|
1
|
+
{"version":3,"file":"signInWithUserPassword.mjs","sources":["../../../../../src/providers/cognito/apis/signInWithUserPassword.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { assertTokenProviderConfig } from '@aws-amplify/core/internals/utils';\nimport { AuthValidationErrorCode } from '../../../errors/types/validation';\nimport { assertServiceError } from '../../../errors/utils/assertServiceError';\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { getActiveSignInUsername, getNewDeviceMetadata, getSignInResult, getSignInResultFromError, handleUserPasswordAuthFlow, retryOnResourceNotFoundException, } from '../utils/signInHelpers';\nimport { resetActiveSignInState, setActiveSignInState, } from '../../../client/utils/store/signInStore';\nimport { cacheCognitoTokens } from '../tokenProvider/cacheTokens';\nimport { tokenOrchestrator } from '../tokenProvider';\nimport { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent';\nimport { resetAutoSignIn } from './autoSignIn';\n/**\n * Signs a user in using USER_PASSWORD_AUTH AuthFlowType\n *\n * @param input - The SignInWithUserPasswordInput object\n * @returns SignInWithUserPasswordOutput\n * @throws service: {@link InitiateAuthException } - Cognito service error thrown during the sign-in process.\n * @throws validation: {@link AuthValidationErrorCode } - Validation errors thrown when either username or password\n * are not defined.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nexport async function signInWithUserPassword(input) {\n const { username, password, options } = input;\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n const signInDetails = {\n loginId: username,\n authFlowType: 'USER_PASSWORD_AUTH',\n };\n assertTokenProviderConfig(authConfig);\n const metadata = options?.clientMetadata;\n assertValidationError(!!username, AuthValidationErrorCode.EmptySignInUsername);\n assertValidationError(!!password, AuthValidationErrorCode.EmptySignInPassword);\n try {\n const { ChallengeName: retiredChallengeName, ChallengeParameters: retriedChallengeParameters, AuthenticationResult, Session, } = await retryOnResourceNotFoundException(handleUserPasswordAuthFlow, [username, password, metadata, authConfig, tokenOrchestrator], username, tokenOrchestrator);\n const activeUsername = getActiveSignInUsername(username);\n // sets up local state used during the sign-in process\n setActiveSignInState({\n signInSession: Session,\n username: activeUsername,\n challengeName: retiredChallengeName,\n signInDetails,\n });\n if (AuthenticationResult) {\n await cacheCognitoTokens({\n ...AuthenticationResult,\n username: activeUsername,\n NewDeviceMetadata: await getNewDeviceMetadata({\n userPoolId: authConfig.userPoolId,\n userPoolEndpoint: authConfig.userPoolEndpoint,\n newDeviceMetadata: AuthenticationResult.NewDeviceMetadata,\n accessToken: AuthenticationResult.AccessToken,\n }),\n signInDetails,\n });\n resetActiveSignInState();\n await dispatchSignedInHubEvent();\n resetAutoSignIn();\n return {\n isSignedIn: true,\n nextStep: { signInStep: 'DONE' },\n };\n }\n return getSignInResult({\n challengeName: retiredChallengeName,\n challengeParameters: retriedChallengeParameters,\n });\n }\n catch (error) {\n resetActiveSignInState();\n resetAutoSignIn();\n assertServiceError(error);\n const result = getSignInResultFromError(error.name);\n if (result)\n return result;\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,sBAAsB,CAAC,KAAK,EAAE;AACpD,IAAI,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAClD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AACzD,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,OAAO,EAAE,QAAQ;AACzB,QAAQ,YAAY,EAAE,oBAAoB;AAC1C,KAAK,CAAC;AACN,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,MAAM,QAAQ,GAAG,OAAO,EAAE,cAAc,CAAC;AAC7C,IAAI,qBAAqB,CAAC,CAAC,CAAC,QAAQ,EAAE,uBAAuB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
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
2
|
+
"name": "@aws-amplify/auth",
|
|
3
|
+
"version": "6.9.0",
|
|
4
|
+
"description": "Auth category of aws-amplify",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.mjs",
|
|
7
|
+
"typings": "./dist/esm/index.d.ts",
|
|
8
|
+
"react-native": "./src/index.ts",
|
|
9
|
+
"sideEffects": [
|
|
10
|
+
"./dist/cjs/providers/cognito/apis/signInWithRedirect.js",
|
|
11
|
+
"./dist/esm/providers/cognito/apis/signInWithRedirect.mjs",
|
|
12
|
+
"./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js",
|
|
13
|
+
"./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "yarn lint --fix && jest -w 1 --coverage --logHeapUsage",
|
|
20
|
+
"build-with-test": "npm test && npm run build",
|
|
21
|
+
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
22
|
+
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
|
|
23
|
+
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
24
|
+
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
|
|
25
|
+
"clean": "npm run clean:size && rimraf lib-esm lib dist",
|
|
26
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
27
|
+
"format": "echo \"Not implemented\"",
|
|
28
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
29
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
30
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 91.18"
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
">=4.2": {
|
|
34
|
+
"cognito": [
|
|
35
|
+
"./dist/esm/providers/cognito/index.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"cognito/server": [
|
|
38
|
+
"./dist/esm/providers/cognito/apis/server/index.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"server": [
|
|
41
|
+
"./dist/esm/server.d.ts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./dist/esm/index.d.ts",
|
|
48
|
+
"import": "./dist/esm/index.mjs",
|
|
49
|
+
"require": "./dist/cjs/index.js",
|
|
50
|
+
"react-native": "./src/index.ts"
|
|
51
|
+
},
|
|
52
|
+
"./cognito": {
|
|
53
|
+
"types": "./dist/esm/providers/cognito/index.d.ts",
|
|
54
|
+
"import": "./dist/esm/providers/cognito/index.mjs",
|
|
55
|
+
"require": "./dist/cjs/providers/cognito/index.js",
|
|
56
|
+
"react-native": "./src/providers/cognito/index.ts"
|
|
57
|
+
},
|
|
58
|
+
"./cognito/server": {
|
|
59
|
+
"types": "./dist/esm/providers/cognito/apis/server/index.d.ts",
|
|
60
|
+
"import": "./dist/esm/providers/cognito/apis/server/index.mjs",
|
|
61
|
+
"require": "./dist/cjs/providers/cognito/apis/server/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./server": {
|
|
64
|
+
"types": "./dist/esm/server.d.ts",
|
|
65
|
+
"import": "./dist/esm/server.mjs",
|
|
66
|
+
"require": "./dist/cjs/server.js"
|
|
67
|
+
},
|
|
68
|
+
"./enable-oauth-listener": {
|
|
69
|
+
"types": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.d.ts",
|
|
70
|
+
"import": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs",
|
|
71
|
+
"require": "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js"
|
|
72
|
+
},
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
78
|
+
},
|
|
79
|
+
"author": "Amazon Web Services",
|
|
80
|
+
"license": "Apache-2.0",
|
|
81
|
+
"bugs": {
|
|
82
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
83
|
+
},
|
|
84
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
85
|
+
"files": [
|
|
86
|
+
"dist/cjs",
|
|
87
|
+
"dist/esm",
|
|
88
|
+
"src",
|
|
89
|
+
"cognito",
|
|
90
|
+
"server",
|
|
91
|
+
"enable-oauth-listener"
|
|
92
|
+
],
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"tslib": "^2.5.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@aws-amplify/core": "^6.1.0"
|
|
98
|
+
},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@aws-amplify/core": "6.8.0",
|
|
101
|
+
"@aws-amplify/react-native": "1.1.6",
|
|
102
|
+
"@jest/test-sequencer": "^29.7.0",
|
|
103
|
+
"typescript": "5.0.2"
|
|
104
|
+
},
|
|
105
|
+
"gitHead": "71558b702db117a4deba51cd23a5a9c455e88bf3"
|
|
106
106
|
}
|
|
@@ -21,11 +21,7 @@ import {
|
|
|
21
21
|
getNewDeviceMetadata,
|
|
22
22
|
getSignInResult,
|
|
23
23
|
} from '../../../providers/cognito/utils/signInHelpers';
|
|
24
|
-
import {
|
|
25
|
-
cleanActiveSignInState,
|
|
26
|
-
setActiveSignInState,
|
|
27
|
-
signInStore,
|
|
28
|
-
} from '../../../client/utils/store';
|
|
24
|
+
import { setActiveSignInState, signInStore } from '../../../client/utils/store';
|
|
29
25
|
import { AuthSignInOutput } from '../../../types';
|
|
30
26
|
import { getAuthUserAgentValue } from '../../../utils';
|
|
31
27
|
import { getPasskey } from '../../utils/passkey';
|
|
@@ -106,7 +102,7 @@ export async function handleWebAuthnSignInResult(
|
|
|
106
102
|
}),
|
|
107
103
|
signInDetails,
|
|
108
104
|
});
|
|
109
|
-
|
|
105
|
+
signInStore.dispatch({ type: 'RESET_STATE' });
|
|
110
106
|
await dispatchSignedInHubEvent();
|
|
111
107
|
|
|
112
108
|
return {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { syncSessionStorage } from '@aws-amplify/core';
|
|
5
|
+
|
|
4
6
|
import { CognitoAuthSignInDetails } from '../../../providers/cognito/types';
|
|
5
7
|
import { ChallengeName } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
|
|
6
8
|
|
|
@@ -19,46 +21,116 @@ type SignInAction =
|
|
|
19
21
|
| { type: 'SET_SIGN_IN_STATE'; value: SignInState }
|
|
20
22
|
| { type: 'SET_USERNAME'; value?: string }
|
|
21
23
|
| { type: 'SET_CHALLENGE_NAME'; value?: ChallengeName }
|
|
22
|
-
| { type: 'SET_SIGN_IN_SESSION'; value?: string }
|
|
24
|
+
| { type: 'SET_SIGN_IN_SESSION'; value?: string }
|
|
25
|
+
| { type: 'RESET_STATE' };
|
|
26
|
+
|
|
27
|
+
// Minutes until stored session invalidates
|
|
28
|
+
const MS_TO_EXPIRY = 3 * 60 * 1000; // 3 mins
|
|
29
|
+
const TGT_STATE = 'CognitoSignInState';
|
|
30
|
+
const SIGN_IN_STATE_KEYS = {
|
|
31
|
+
username: `${TGT_STATE}.username`,
|
|
32
|
+
challengeName: `${TGT_STATE}.challengeName`,
|
|
33
|
+
signInSession: `${TGT_STATE}.signInSession`,
|
|
34
|
+
expiry: `${TGT_STATE}.expiry`,
|
|
35
|
+
};
|
|
23
36
|
|
|
24
37
|
const signInReducer: Reducer<SignInState, SignInAction> = (state, action) => {
|
|
25
38
|
switch (action.type) {
|
|
26
39
|
case 'SET_SIGN_IN_SESSION':
|
|
40
|
+
persistSignInState({ signInSession: action.value });
|
|
41
|
+
|
|
27
42
|
return {
|
|
28
43
|
...state,
|
|
29
44
|
signInSession: action.value,
|
|
30
45
|
};
|
|
46
|
+
|
|
31
47
|
case 'SET_SIGN_IN_STATE':
|
|
48
|
+
persistSignInState(action.value);
|
|
49
|
+
|
|
32
50
|
return {
|
|
33
51
|
...action.value,
|
|
34
52
|
};
|
|
53
|
+
|
|
35
54
|
case 'SET_CHALLENGE_NAME':
|
|
55
|
+
persistSignInState({ challengeName: action.value });
|
|
56
|
+
|
|
36
57
|
return {
|
|
37
58
|
...state,
|
|
38
59
|
challengeName: action.value,
|
|
39
60
|
};
|
|
61
|
+
|
|
40
62
|
case 'SET_USERNAME':
|
|
63
|
+
persistSignInState({ username: action.value });
|
|
64
|
+
|
|
41
65
|
return {
|
|
42
66
|
...state,
|
|
43
67
|
username: action.value,
|
|
44
68
|
};
|
|
69
|
+
|
|
45
70
|
case 'SET_INITIAL_STATE':
|
|
46
|
-
return
|
|
71
|
+
return getInitialState();
|
|
72
|
+
|
|
73
|
+
case 'RESET_STATE':
|
|
74
|
+
clearPersistedSignInState();
|
|
75
|
+
|
|
76
|
+
return getDefaultState();
|
|
77
|
+
|
|
78
|
+
// this state is never reachable
|
|
47
79
|
default:
|
|
48
80
|
return state;
|
|
49
81
|
}
|
|
50
82
|
};
|
|
51
83
|
|
|
52
|
-
|
|
84
|
+
const isExpired = (expiryDate: string | null): boolean => {
|
|
85
|
+
const expiryTimestamp = Number(expiryDate);
|
|
86
|
+
const currentTimestamp = Date.now();
|
|
87
|
+
|
|
88
|
+
return expiryTimestamp <= currentTimestamp;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const resetActiveSignInState = () => {
|
|
92
|
+
signInStore.dispatch({ type: 'RESET_STATE' });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const clearPersistedSignInState = () => {
|
|
96
|
+
for (const stateKey of Object.values(SIGN_IN_STATE_KEYS)) {
|
|
97
|
+
syncSessionStorage.removeItem(stateKey);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getDefaultState = (): SignInState => ({
|
|
102
|
+
username: undefined,
|
|
103
|
+
challengeName: undefined,
|
|
104
|
+
signInSession: undefined,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Hydrate signInStore from syncSessionStorage
|
|
108
|
+
const getInitialState = (): SignInState => {
|
|
109
|
+
const expiry = syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.expiry);
|
|
110
|
+
|
|
111
|
+
if (!expiry || isExpired(expiry)) {
|
|
112
|
+
clearPersistedSignInState();
|
|
113
|
+
|
|
114
|
+
return getDefaultState();
|
|
115
|
+
}
|
|
116
|
+
const username =
|
|
117
|
+
syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.username) ?? undefined;
|
|
118
|
+
|
|
119
|
+
const challengeName = (syncSessionStorage.getItem(
|
|
120
|
+
SIGN_IN_STATE_KEYS.challengeName,
|
|
121
|
+
) ?? undefined) as ChallengeName;
|
|
122
|
+
const signInSession =
|
|
123
|
+
syncSessionStorage.getItem(SIGN_IN_STATE_KEYS.signInSession) ?? undefined;
|
|
124
|
+
|
|
53
125
|
return {
|
|
54
|
-
username
|
|
55
|
-
challengeName
|
|
56
|
-
signInSession
|
|
126
|
+
username,
|
|
127
|
+
challengeName,
|
|
128
|
+
signInSession,
|
|
57
129
|
};
|
|
58
|
-
}
|
|
130
|
+
};
|
|
59
131
|
|
|
60
132
|
const createStore: Store<SignInState, SignInAction> = reducer => {
|
|
61
|
-
let currentState = reducer(
|
|
133
|
+
let currentState = reducer(getDefaultState(), { type: 'SET_INITIAL_STATE' });
|
|
62
134
|
|
|
63
135
|
return {
|
|
64
136
|
getState: () => currentState,
|
|
@@ -77,6 +149,23 @@ export function setActiveSignInState(state: SignInState): void {
|
|
|
77
149
|
});
|
|
78
150
|
}
|
|
79
151
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
152
|
+
// Save local state into Session Storage
|
|
153
|
+
export const persistSignInState = ({
|
|
154
|
+
challengeName,
|
|
155
|
+
signInSession,
|
|
156
|
+
username,
|
|
157
|
+
}: SignInState) => {
|
|
158
|
+
username && syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.username, username);
|
|
159
|
+
challengeName &&
|
|
160
|
+
syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.challengeName, challengeName);
|
|
161
|
+
|
|
162
|
+
if (signInSession) {
|
|
163
|
+
syncSessionStorage.setItem(SIGN_IN_STATE_KEYS.signInSession, signInSession);
|
|
164
|
+
|
|
165
|
+
// Updates expiry when session is passed
|
|
166
|
+
syncSessionStorage.setItem(
|
|
167
|
+
SIGN_IN_STATE_KEYS.expiry,
|
|
168
|
+
String(Date.now() + MS_TO_EXPIRY),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '../types/errors';
|
|
12
12
|
import { ConfirmSignInInput, ConfirmSignInOutput } from '../types';
|
|
13
13
|
import {
|
|
14
|
-
|
|
14
|
+
resetActiveSignInState,
|
|
15
15
|
setActiveSignInState,
|
|
16
16
|
signInStore,
|
|
17
17
|
} from '../../../client/utils/store';
|
|
@@ -120,7 +120,7 @@ export async function confirmSignIn(
|
|
|
120
120
|
}),
|
|
121
121
|
signInDetails,
|
|
122
122
|
});
|
|
123
|
-
|
|
123
|
+
resetActiveSignInState();
|
|
124
124
|
|
|
125
125
|
await dispatchSignedInHubEvent();
|
|
126
126
|
|
|
@@ -22,9 +22,9 @@ import {
|
|
|
22
22
|
SignInWithCustomAuthOutput,
|
|
23
23
|
} from '../types';
|
|
24
24
|
import {
|
|
25
|
-
|
|
25
|
+
resetActiveSignInState,
|
|
26
26
|
setActiveSignInState,
|
|
27
|
-
} from '../../../client/utils/store';
|
|
27
|
+
} from '../../../client/utils/store/signInStore';
|
|
28
28
|
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
|
|
29
29
|
import {
|
|
30
30
|
ChallengeName,
|
|
@@ -95,7 +95,7 @@ export async function signInWithCustomAuth(
|
|
|
95
95
|
}),
|
|
96
96
|
signInDetails,
|
|
97
97
|
});
|
|
98
|
-
|
|
98
|
+
resetActiveSignInState();
|
|
99
99
|
|
|
100
100
|
await dispatchSignedInHubEvent();
|
|
101
101
|
|
|
@@ -110,7 +110,7 @@ export async function signInWithCustomAuth(
|
|
|
110
110
|
challengeParameters: retiredChallengeParameters as ChallengeParameters,
|
|
111
111
|
});
|
|
112
112
|
} catch (error) {
|
|
113
|
-
|
|
113
|
+
resetActiveSignInState();
|
|
114
114
|
assertServiceError(error);
|
|
115
115
|
const result = getSignInResultFromError(error.name);
|
|
116
116
|
if (result) return result;
|
|
@@ -24,9 +24,9 @@ import {
|
|
|
24
24
|
SignInWithCustomSRPAuthOutput,
|
|
25
25
|
} from '../types';
|
|
26
26
|
import {
|
|
27
|
-
|
|
27
|
+
resetActiveSignInState,
|
|
28
28
|
setActiveSignInState,
|
|
29
|
-
} from '../../../client/utils/store';
|
|
29
|
+
} from '../../../client/utils/store/signInStore';
|
|
30
30
|
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
|
|
31
31
|
import {
|
|
32
32
|
ChallengeName,
|
|
@@ -100,7 +100,7 @@ export async function signInWithCustomSRPAuth(
|
|
|
100
100
|
}),
|
|
101
101
|
signInDetails,
|
|
102
102
|
});
|
|
103
|
-
|
|
103
|
+
resetActiveSignInState();
|
|
104
104
|
|
|
105
105
|
await dispatchSignedInHubEvent();
|
|
106
106
|
|
|
@@ -115,7 +115,7 @@ export async function signInWithCustomSRPAuth(
|
|
|
115
115
|
challengeParameters: handledChallengeParameters as ChallengeParameters,
|
|
116
116
|
});
|
|
117
117
|
} catch (error) {
|
|
118
|
-
|
|
118
|
+
resetActiveSignInState();
|
|
119
119
|
assertServiceError(error);
|
|
120
120
|
const result = getSignInResultFromError(error.name);
|
|
121
121
|
if (result) return result;
|
|
@@ -28,9 +28,9 @@ import {
|
|
|
28
28
|
SignInWithSRPOutput,
|
|
29
29
|
} from '../types';
|
|
30
30
|
import {
|
|
31
|
-
|
|
31
|
+
resetActiveSignInState,
|
|
32
32
|
setActiveSignInState,
|
|
33
|
-
} from '../../../client/utils/store';
|
|
33
|
+
} from '../../../client/utils/store/signInStore';
|
|
34
34
|
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
|
|
35
35
|
import { tokenOrchestrator } from '../tokenProvider';
|
|
36
36
|
import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent';
|
|
@@ -102,7 +102,7 @@ export async function signInWithSRP(
|
|
|
102
102
|
}),
|
|
103
103
|
signInDetails,
|
|
104
104
|
});
|
|
105
|
-
|
|
105
|
+
resetActiveSignInState();
|
|
106
106
|
|
|
107
107
|
await dispatchSignedInHubEvent();
|
|
108
108
|
|
|
@@ -119,7 +119,7 @@ export async function signInWithSRP(
|
|
|
119
119
|
challengeParameters: handledChallengeParameters as ChallengeParameters,
|
|
120
120
|
});
|
|
121
121
|
} catch (error) {
|
|
122
|
-
|
|
122
|
+
resetActiveSignInState();
|
|
123
123
|
resetAutoSignIn();
|
|
124
124
|
assertServiceError(error);
|
|
125
125
|
const result = getSignInResultFromError(error.name);
|
|
@@ -26,11 +26,11 @@ import {
|
|
|
26
26
|
SignInWithUserAuthInput,
|
|
27
27
|
SignInWithUserAuthOutput,
|
|
28
28
|
} from '../types';
|
|
29
|
+
import { autoSignInStore } from '../../../client/utils/store';
|
|
29
30
|
import {
|
|
30
|
-
|
|
31
|
-
cleanActiveSignInState,
|
|
31
|
+
resetActiveSignInState,
|
|
32
32
|
setActiveSignInState,
|
|
33
|
-
} from '../../../client/utils/store';
|
|
33
|
+
} from '../../../client/utils/store/signInStore';
|
|
34
34
|
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
|
|
35
35
|
import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent';
|
|
36
36
|
import { tokenOrchestrator } from '../tokenProvider';
|
|
@@ -111,7 +111,7 @@ export async function signInWithUserAuth(
|
|
|
111
111
|
}),
|
|
112
112
|
signInDetails,
|
|
113
113
|
});
|
|
114
|
-
|
|
114
|
+
resetActiveSignInState();
|
|
115
115
|
|
|
116
116
|
await dispatchSignedInHubEvent();
|
|
117
117
|
|
|
@@ -132,7 +132,7 @@ export async function signInWithUserAuth(
|
|
|
132
132
|
: undefined,
|
|
133
133
|
});
|
|
134
134
|
} catch (error) {
|
|
135
|
-
|
|
135
|
+
resetActiveSignInState();
|
|
136
136
|
resetAutoSignIn();
|
|
137
137
|
assertServiceError(error);
|
|
138
138
|
const result = getSignInResultFromError(error.name);
|
|
@@ -26,9 +26,9 @@ import {
|
|
|
26
26
|
SignInWithUserPasswordOutput,
|
|
27
27
|
} from '../types';
|
|
28
28
|
import {
|
|
29
|
-
|
|
29
|
+
resetActiveSignInState,
|
|
30
30
|
setActiveSignInState,
|
|
31
|
-
} from '../../../client/utils/store';
|
|
31
|
+
} from '../../../client/utils/store/signInStore';
|
|
32
32
|
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
|
|
33
33
|
import { tokenOrchestrator } from '../tokenProvider';
|
|
34
34
|
import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent';
|
|
@@ -97,7 +97,7 @@ export async function signInWithUserPassword(
|
|
|
97
97
|
}),
|
|
98
98
|
signInDetails,
|
|
99
99
|
});
|
|
100
|
-
|
|
100
|
+
resetActiveSignInState();
|
|
101
101
|
|
|
102
102
|
await dispatchSignedInHubEvent();
|
|
103
103
|
|
|
@@ -114,7 +114,7 @@ export async function signInWithUserPassword(
|
|
|
114
114
|
challengeParameters: retriedChallengeParameters as ChallengeParameters,
|
|
115
115
|
});
|
|
116
116
|
} catch (error) {
|
|
117
|
-
|
|
117
|
+
resetActiveSignInState();
|
|
118
118
|
resetAutoSignIn();
|
|
119
119
|
assertServiceError(error);
|
|
120
120
|
const result = getSignInResultFromError(error.name);
|