Skip to content

Commit

Permalink
fix(auth): add signInDetails on refreshTokens action (#13153)
Browse files Browse the repository at this point in the history
* fix(auth): add signInDetails on refreshTokens action

* chore: use object destructuring

* chore: remove console log
  • Loading branch information
israx authored Mar 21, 2024
1 parent 1a6d358 commit 1aafa48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jest.mock('@aws-amplify/core', () => ({
},
}));

const mockAssertTokenProviderConfig = assertTokenProviderConfig as jest.Mock;

describe('tokenOrchestrator', () => {
const mockTokenRefresher = jest.fn();
const mockTokenStore = {
Expand All @@ -36,14 +34,19 @@ describe('tokenOrchestrator', () => {
describe('refreshTokens method', () => {
it('calls the set tokenRefresher, tokenStore and Hub while refreshing tokens', async () => {
const testUsername = 'username';
const testSignInDetails= {
authFlowType:'CUSTOM_WITHOUT_SRP',
loginId: testUsername
} as const;
const testInputTokens = {
accessToken: {
payload: {},
},
clockDrift: 400000,
username: testUsername,
signInDetails:testSignInDetails
};

// mock tokens should not include signInDetails
const mockTokens: CognitoAuthTokens = {
accessToken: {
payload: {},
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('tokenOrchestrator', () => {

// ensure the result is correct
expect(newTokens).toEqual(mockTokens);
expect(newTokens?.signInDetails).toEqual(testSignInDetails)
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
username: string;
}): Promise<CognitoAuthTokens | null> {
try {
const { signInDetails } = tokens;
const newTokens = await this.getTokenRefresher()({
tokens,
authConfig: this.authConfig,
username,
});

newTokens.signInDetails = signInDetails;
await this.setTokens({ tokens: newTokens });
Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', AMPLIFY_SYMBOL);

Expand Down

0 comments on commit 1aafa48

Please sign in to comment.