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(auth): add inflightPromise in token orchestrator #13158

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@
import { AuthError } from '../../../errors/AuthError';
import { CognitoAuthSignInDetails } from '../types';

import {

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

View workflow job for this annotation

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

There should be at least one empty line between import groups

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

View workflow job for this annotation

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

`./types` import should occur after import of `../utils/oauth/inflightPromise`
AuthTokenOrchestrator,
AuthTokenStore,
CognitoAuthTokens,
DeviceMetadata,
TokenRefresher,
} from './types';
import { oAuthStore } from '../utils/oauth';
import { addInflightPromise } from '../utils/oauth/inflightPromise';

export class TokenOrchestrator implements AuthTokenOrchestrator {
private authConfig?: AuthConfig;
tokenStore?: AuthTokenStore;
tokenRefresher?: TokenRefresher;
waitForInflightOAuth: () => Promise<void> = async () => {
// no-op
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Not a no-op anymore

if (!(await oAuthStore.loadOAuthInFlight())) {
return;
}

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

View workflow job for this annotation

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

Trailing spaces not allowed

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

View workflow job for this annotation

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

Delete `↹↹`
return new Promise<void>((resolve, _reject) => {
addInflightPromise(resolve);
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove the addInflightPromise() call from attempCompleteOAuthFlow then?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah good point

Copy link
Member

Choose a reason for hiding this comment

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

cognitoUserPoolsTokenProvider.setWaitForInflightOAuth should be removed as well as its single use case is being replace by this. 👍

});

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

View workflow job for this annotation

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

Delete `⏎`

};

setAuthConfig(authConfig: AuthConfig) {
Expand Down Expand Up @@ -83,6 +93,7 @@
// Token provider not configured
return null;
}

await this.waitForInflightOAuth();
tokens = await this.getTokenStore().loadTokens();
const username = await this.getTokenStore().getLastAuthUser();
Expand Down
Loading