diff --git a/packages/auth/__tests__/providers/cognito/deleteUser.test.ts b/packages/auth/__tests__/providers/cognito/deleteUser.test.ts index fcf7e45bdf1..76996d8c7fc 100644 --- a/packages/auth/__tests__/providers/cognito/deleteUser.test.ts +++ b/packages/auth/__tests__/providers/cognito/deleteUser.test.ts @@ -84,12 +84,13 @@ describe('deleteUser API happy path cases', () => { }) ); expect(deleteUserClientSpy).toBeCalledTimes(1); + expect(tokenOrchestratorSpy).toHaveBeenCalledTimes(1); + expect(signOutApiSpy).toHaveBeenCalledTimes(1); - // signout - expect(signOutApiSpy).toBeCalledTimes(1); - - // clear device tokens - expect(tokenOrchestratorSpy).toBeCalled(); + // make sure we clearDeviceToken -> signout, in that order + expect(tokenOrchestratorSpy.mock.invocationCallOrder[0]).toBeLessThan( + signOutApiSpy.mock.invocationCallOrder[0] + ); }); }); diff --git a/packages/auth/src/providers/cognito/apis/deleteUser.ts b/packages/auth/src/providers/cognito/apis/deleteUser.ts index 68c609e765d..3f32627c712 100644 --- a/packages/auth/src/providers/cognito/apis/deleteUser.ts +++ b/packages/auth/src/providers/cognito/apis/deleteUser.ts @@ -2,7 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { assertTokenProviderConfig, AuthAction } from '@aws-amplify/core/internals/utils'; +import { + assertTokenProviderConfig, + AuthAction, +} from '@aws-amplify/core/internals/utils'; import { fetchAuthSession } from '../../../'; import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils'; import { assertAuthTokens } from '../utils/types'; @@ -26,14 +29,14 @@ export async function deleteUser(): Promise { assertAuthTokens(tokens); await serviceDeleteUser( - { + { region: getRegion(authConfig.userPoolId), - userAgentValue: getAuthUserAgentValue(AuthAction.DeleteUser) + userAgentValue: getAuthUserAgentValue(AuthAction.DeleteUser), }, { AccessToken: tokens.accessToken.toString(), } ); - await signOut(); await tokenOrchestrator.clearDeviceMetadata(); + await signOut(); }