diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ea2582a6d47..ae62578be5e 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,6 +120,7 @@ export async function confirmSignIn( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 348c60870ae..5911266475b 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,6 +95,7 @@ export async function signInWithCustomAuth( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 4cff40e7cd7..aa92e3e6012 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,6 +102,7 @@ export async function signInWithSRP( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 9ac1223a105..94165046864 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..8027af90c71 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,6 +97,7 @@ export async function signInWithUserPassword( }), signInDetails, }); + cleanActiveSignInState(); await dispatchSignedInHubEvent();