Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr-adapter): refreshToken may return the same tokens across requests #13387

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Just rename refreshAuthTokensFunction -> refreshAuthTokensWithoutDedupe and export it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do this later, as I'm thinking of a different solution to create dedupe edition for SSR use cases.

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
Loading