From 3c1cc8f9c46d5f7444f790792dcdbd74b88e07e6 Mon Sep 17 00:00:00 2001 From: Zhi Zhou Date: Wed, 4 Dec 2024 16:59:12 +0800 Subject: [PATCH 1/2] refactor: clean signIn state after all relevant async works finish --- packages/auth/src/providers/cognito/apis/confirmSignIn.ts | 4 ++-- .../auth/src/providers/cognito/apis/signInWithCustomAuth.ts | 5 ++--- packages/auth/src/providers/cognito/apis/signInWithSRP.ts | 4 ++-- .../auth/src/providers/cognito/apis/signInWithUserAuth.ts | 3 ++- .../src/providers/cognito/apis/signInWithUserPassword.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ea2582a6d47..34eab302ef9 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -109,7 +109,6 @@ export async function confirmSignIn( }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username, ...AuthenticationResult, @@ -121,7 +120,8 @@ export async function confirmSignIn( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 348c60870ae..d82b28f3ead 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -84,8 +84,6 @@ export async function signInWithCustomAuth( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); - await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -97,7 +95,8 @@ export async function signInWithCustomAuth( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 4cff40e7cd7..46e8fc7dcb3 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -91,7 +91,6 @@ export async function signInWithSRP( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -103,7 +102,8 @@ export async function signInWithSRP( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 9ac1223a105..7c182cf22bd 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -100,7 +100,6 @@ export async function signInWithUserAuth( }); if (response.AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...response.AuthenticationResult, @@ -112,6 +111,8 @@ export async function signInWithUserAuth( }), signInDetails, }); + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 0cd3acd88d3..c5386b7d6d7 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -86,7 +86,6 @@ export async function signInWithUserPassword( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ ...AuthenticationResult, username: activeUsername, @@ -98,7 +97,8 @@ export async function signInWithUserPassword( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); From 07798249fbdbdf6720e85bdce1ce10bf9485a4d5 Mon Sep 17 00:00:00 2001 From: James Jarvis Date: Fri, 6 Dec 2024 10:06:41 -0800 Subject: [PATCH 2/2] chore: lint code changes --- packages/auth/src/providers/cognito/apis/confirmSignIn.ts | 2 +- .../auth/src/providers/cognito/apis/signInWithCustomAuth.ts | 2 +- packages/auth/src/providers/cognito/apis/signInWithSRP.ts | 2 +- packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts | 2 +- .../auth/src/providers/cognito/apis/signInWithUserPassword.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index 34eab302ef9..ae62578be5e 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -121,7 +121,7 @@ export async function confirmSignIn( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index d82b28f3ead..5911266475b 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -96,7 +96,7 @@ export async function signInWithCustomAuth( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 46e8fc7dcb3..aa92e3e6012 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -103,7 +103,7 @@ export async function signInWithSRP( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 7c182cf22bd..94165046864 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -112,7 +112,7 @@ export async function signInWithUserAuth( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index c5386b7d6d7..8027af90c71 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -98,7 +98,7 @@ export async function signInWithUserPassword( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn();