@@ -182,7 +182,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
182
182
}
183
183
184
184
// Update current Auth state. Either a new login or logout.
185
- await this . _updateCurrentUser ( user ) ;
185
+ // Skip blocking callbacks, they should not apply to a change in another tab.
186
+ await this . _updateCurrentUser ( user , /* skipBeforeStateCallbacks */ true ) ;
186
187
}
187
188
188
189
private async initializeCurrentUser (
@@ -314,7 +315,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
314
315
return this . _updateCurrentUser ( user && user . _clone ( this ) ) ;
315
316
}
316
317
317
- async _updateCurrentUser ( user : User | null ) : Promise < void > {
318
+ async _updateCurrentUser ( user : User | null , skipBeforeStateCallbacks : boolean = false ) : Promise < void > {
318
319
if ( this . _deleted ) {
319
320
return ;
320
321
}
@@ -325,7 +326,10 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
325
326
AuthErrorCode . TENANT_ID_MISMATCH
326
327
) ;
327
328
}
328
- await this . _runBeforeStateCallbacks ( user ) ;
329
+
330
+ if ( ! skipBeforeStateCallbacks ) {
331
+ await this . _runBeforeStateCallbacks ( user ) ;
332
+ }
329
333
330
334
return this . queue ( async ( ) => {
331
335
await this . directlySetCurrentUser ( user as UserInternal | null ) ;
@@ -339,18 +343,22 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
339
343
await beforeStateCallback ( user ) ;
340
344
}
341
345
} catch ( e ) {
342
- throw this . _errorFactory . create ( AuthErrorCode . LOGIN_BLOCKED , { message : e . message } ) ;
346
+ throw this . _errorFactory . create (
347
+ AuthErrorCode . LOGIN_BLOCKED , { originalMessage : e . message } ) ;
343
348
}
344
349
}
345
350
346
351
async signOut ( ) : Promise < void > {
352
+ // Run first, to block _setRedirectUser() if any callbacks fail.
347
353
await this . _runBeforeStateCallbacks ( null ) ;
348
354
// Clear the redirect user when signOut is called
349
355
if ( this . redirectPersistenceManager || this . _popupRedirectResolver ) {
350
356
await this . _setRedirectUser ( null ) ;
351
357
}
352
358
353
- return this . _updateCurrentUser ( null ) ;
359
+ // Prevent callbacks from being called again in _updateCurrentUser, as
360
+ // they were already called in the first line.
361
+ return this . _updateCurrentUser ( null , /* skipBeforeStateCallbacks */ true ) ;
354
362
}
355
363
356
364
setPersistence ( persistence : Persistence ) : Promise < void > {
0 commit comments