Skip to content

Commit 1d6771e

Browse files
authored
Wait for upto 8s for IDP sign in to finish, after popup is closed. (#7140)
* Wait for upto 8s for IDP sign in to finish, after popup is closed. In some cases (Fiefox or mobile or if opener is an iframe), the popup is closed by the oauth helper code right after sign in has completed at the IDP. The IDP response still needs to be processed by the SDK + signInWithIdp API call needs to be invoked. This can take upto 7s, if there is a blocking function configured. Increase the poller timeout to 8s, so it does not reject the sign in with popup-closed-by-user error. increase timeout for the aborted sign in test. * Add changeset.
1 parent ecb4454 commit 1d6771e

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/dry-cats-lick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Increase the popup poller timeout to 8s to support blocking functions + Firefox

packages/auth/src/platform_browser/strategies/popup.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ import { FederatedAuthProvider } from '../../core/providers/federated';
4646
import { getModularInstance } from '@firebase/util';
4747

4848
/*
49-
* The event timeout is the same on mobile and desktop, no need for Delay.
49+
* The event timeout is the same on mobile and desktop, no need for Delay. Set this to 8s since
50+
* blocking functions can take upto 7s to complete sign in, as documented in:
51+
* https://cloud.google.com/identity-platform/docs/blocking-functions#understanding_blocking_functions
52+
* https://firebase.google.com/docs/auth/extend-with-blocking-functions#understanding_blocking_functions
5053
*/
5154
export const enum _Timeout {
52-
AUTH_EVENT = 2000
55+
AUTH_EVENT = 8000
5356
}
5457
export const _POLL_WINDOW_CLOSE_TIMEOUT = new Delay(2000, 10000);
5558

@@ -282,7 +285,9 @@ class PopupOperation extends AbstractPopupRedirectOperation {
282285
if (this.authWindow?.window?.closed) {
283286
// Make sure that there is sufficient time for whatever action to
284287
// complete. The window could have closed but the sign in network
285-
// call could still be in flight.
288+
// call could still be in flight. This is specifically true for
289+
// Firefox or if the opener is in an iframe, in which case the oauth
290+
// helper closes the popup.
286291
this.pollId = window.setTimeout(() => {
287292
this.pollId = null;
288293
this.reject(

packages/auth/test/integration/webdriver/popup.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ browserDescribe('Popup IdP tests', driver => {
192192
await widget.fillEmail('[email protected]');
193193
await widget.clickSignIn();
194194

195-
// On redirect, check that the signed in user is different
195+
// On return to main window, check that the signed in user is different
196196
await driver.selectMainWindow();
197197
const curUser = await driver.getUserSnapshot();
198198
expect(curUser.uid).not.to.eq(anonUser.uid);
@@ -210,7 +210,7 @@ browserDescribe('Popup IdP tests', driver => {
210210
await widget.fillEmail('[email protected]');
211211
await widget.clickSignIn();
212212

213-
// On redirect, check that the signed in user is upgraded
213+
// On return to main window, check that the signed in user is upgraded
214214
await driver.selectMainWindow();
215215
const curUser = await driver.getUserSnapshot();
216216
expect(curUser.uid).to.eq(anonUser.uid);
@@ -396,6 +396,7 @@ browserDescribe('Popup IdP tests', driver => {
396396
user = await driver.getUserSnapshot();
397397
expect(user.uid).to.eq(user1.uid);
398398
expect(user.email).to.eq(user1.email);
399-
}).timeout(12_000); // Test takes a while due to the closed-by-user errors
399+
}).timeout(25_000); // Test takes a while due to the closed-by-user errors. Each closed-by-user
400+
// takes 8s to timeout, and we have 2 instances.
400401
});
401402
});

0 commit comments

Comments
 (0)