Skip to content

Commit

Permalink
fix(ssr-adapter): refreshToken may return the same tokens across requ…
Browse files Browse the repository at this point in the history
…ests (#13387)

fix(auth): deduped refreshToken utility causes using same accessToken on the server side
  • Loading branch information
HuiSF authored May 15, 2024
1 parent a538798 commit 2e5e2f1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/auth/src/providers/cognito/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ export {
TokenOrchestrator,
DefaultTokenStore,
refreshAuthTokens,
refreshAuthTokensWithoutDedupe,
} from './tokenProvider';
5 changes: 4 additions & 1 deletion packages/auth/src/providers/cognito/tokenProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export { refreshAuthTokens } from '../utils/refreshAuthTokens';
export {
refreshAuthTokens,
refreshAuthTokensWithoutDedupe,
} from '../utils/refreshAuthTokens';
export { DefaultTokenStore } from './TokenStore';
export { TokenOrchestrator } from './TokenOrchestrator';
export { CognitoUserPoolTokenProviderType } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ const refreshAuthTokensFunction: TokenRefresher = async ({
};

export const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);
export const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
DefaultTokenStore,
TokenOrchestrator,
refreshAuthTokens,
refreshAuthTokensWithoutDedupe,
} from '@aws-amplify/auth/cognito';
import { AuthConfig, KeyValueStorageInterface } from '@aws-amplify/core';

Expand All @@ -27,7 +27,7 @@ const mockAuthConfig: AuthConfig = {
};
const MockDefaultTokenStore = DefaultTokenStore as jest.Mock;
const MockTokenOrchestrator = TokenOrchestrator as jest.Mock;
const mockRefreshAuthTokens = refreshAuthTokens as jest.Mock;
const mockRefreshAuthTokens = refreshAuthTokensWithoutDedupe as jest.Mock;

describe('createUserPoolsTokenProvider', () => {
beforeEach(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/aws-amplify/__tests__/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ describe('aws-amplify Exports', () => {
'TokenOrchestrator',
'DefaultTokenStore',
'refreshAuthTokens',
'refreshAuthTokensWithoutDedupe',
].sort(),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
DefaultTokenStore,
TokenOrchestrator,
refreshAuthTokens,
refreshAuthTokensWithoutDedupe,
} from '@aws-amplify/auth/cognito';
import {
AuthConfig,
Expand All @@ -28,7 +28,7 @@ export const createUserPoolsTokenProvider = (
const tokenOrchestrator = new TokenOrchestrator();
tokenOrchestrator.setAuthConfig(authConfig);
tokenOrchestrator.setAuthTokenStore(authTokenStore);
tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
tokenOrchestrator.setTokenRefresher(refreshAuthTokensWithoutDedupe);

return {
getTokens: ({ forceRefresh } = { forceRefresh: false }) =>
Expand Down

0 comments on commit 2e5e2f1

Please sign in to comment.