Skip to content

Commit

Permalink
fix: Prevent race condition in login flow (#484)
Browse files Browse the repository at this point in the history
Initalise completeLoginConditions at start of login to prevent race conditions.
  • Loading branch information
jeswr authored Nov 13, 2023
1 parent c166230 commit 8297209
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/internal-playwright-helpers/src/flows/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export class AuthFlow {
const testPage = new TestPage(this.page, this.openidProvider);
const cognitoPage = new CognitoPage(this.page);
const openIdPage = new OpenIdPage(this.page);
// Clicking on the consent screen from the broker will redirect to the
// test page, and trigger the token request. To prevent this being a
// race condition, waiting on this request should be done prior to
// giving consent.
const completeLoginConditions = [testPage.handleRedirect()];

// First, initiate login in the test client, and wait for the redirect to the OP
await Promise.all([
this.page.waitForURL(
Expand All @@ -79,11 +85,6 @@ export class AuthFlow {
]);
}

// Clicking on the consent screen from the broker will redirect to the
// test page, and trigger the token request. To prevent this being a
// race condition, waiting on this request should be done prior to
// giving consent.
const completeLoginConditions = [testPage.handleRedirect()];
// TODO: handle allow === false
if (options.allow && OpenIdPage.isOnPage(new URL(this.page.url()))) {
completeLoginConditions.push(openIdPage.allow(timeoutOptions));
Expand Down

0 comments on commit 8297209

Please sign in to comment.