Skip to content

Commit

Permalink
fix(auth): add signInDetails on refreshTokens action
Browse files Browse the repository at this point in the history
  • Loading branch information
israx committed Mar 20, 2024
1 parent bd1fefd commit eb1f5c6
Show file tree
Hide file tree
Showing 2 changed files with 10 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 All @@ -58,6 +61,7 @@ describe('tokenOrchestrator', () => {
username: testUsername,
});

console.log(newTokens);
// ensure the underlying async operations to be completed
// async #1
expect(mockTokenRefresher).toHaveBeenCalledWith(
Expand All @@ -71,6 +75,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.signInDetails;

Check failure on line 130 in packages/auth/src/providers/cognito/tokenProvider/TokenOrchestrator.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/auth

Use object destructuring
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 eb1f5c6

Please sign in to comment.