diff --git a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts index 2589f9d49d3..ec40dc85a22 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts @@ -17,6 +17,14 @@ describe('signInWithRedirect API', () => { it('should try to clear oauth data before starting an oauth flow.', async () => { // TODO: ADD Test: previous test was invalid }); + + it('should call `assertUserNotAuthenticated` by default', async () => { + // TODO: ADD Test + }); + + it('should not call `assertUserNotAuthenticated` when skip set to true', async () => { + // TODO: ADD Test + }); }); describe('getRedirectUrl on web', () => { diff --git a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts index 76f99752cf1..a9c048a3e11 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts @@ -44,7 +44,9 @@ export async function signInWithRedirect( assertTokenProviderConfig(authConfig); assertOAuthConfig(authConfig); store.setAuthConfig(authConfig); - await assertUserNotAuthenticated(); + if (input?.options?.skipAssertUserNotAuthenticated !== true) { + await assertUserNotAuthenticated(); + } let provider = 'COGNITO'; // Default diff --git a/packages/auth/src/types/inputs.ts b/packages/auth/src/types/inputs.ts index 1f8aa0ddb3e..801c7ecb07b 100644 --- a/packages/auth/src/types/inputs.ts +++ b/packages/auth/src/types/inputs.ts @@ -65,6 +65,10 @@ export type AuthSignInWithRedirectInput = { * On all other platforms, this flag is ignored. */ preferPrivateSession?: boolean; + /** + * Setting this to true will allow you to sign in even when a user is authenticated. + */ + skipAssertUserNotAuthenticated?: boolean; }; };