Skip to content

Commit

Permalink
fix(auth): deleteUser clear deviceTokens then signout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Kumar committed Oct 6, 2023
1 parent 2dc407c commit 5bff898
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/auth/__tests__/providers/cognito/deleteUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
});
});

Expand Down
11 changes: 7 additions & 4 deletions packages/auth/src/providers/cognito/apis/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,14 +29,14 @@ export async function deleteUser(): Promise<void> {
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();
}

0 comments on commit 5bff898

Please sign in to comment.