@@ -182,7 +182,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
182182 }
183183
184184 // 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 ) ;
186187 }
187188
188189 private async initializeCurrentUser (
@@ -314,7 +315,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
314315 return this . _updateCurrentUser ( user && user . _clone ( this ) ) ;
315316 }
316317
317- async _updateCurrentUser ( user : User | null ) : Promise < void > {
318+ async _updateCurrentUser ( user : User | null , skipBeforeStateCallbacks : boolean = false ) : Promise < void > {
318319 if ( this . _deleted ) {
319320 return ;
320321 }
@@ -325,7 +326,10 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
325326 AuthErrorCode . TENANT_ID_MISMATCH
326327 ) ;
327328 }
328- await this . _runBeforeStateCallbacks ( user ) ;
329+
330+ if ( ! skipBeforeStateCallbacks ) {
331+ await this . _runBeforeStateCallbacks ( user ) ;
332+ }
329333
330334 return this . queue ( async ( ) => {
331335 await this . directlySetCurrentUser ( user as UserInternal | null ) ;
@@ -339,18 +343,22 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
339343 await beforeStateCallback ( user ) ;
340344 }
341345 } 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 } ) ;
343348 }
344349 }
345350
346351 async signOut ( ) : Promise < void > {
352+ // Run first, to block _setRedirectUser() if any callbacks fail.
347353 await this . _runBeforeStateCallbacks ( null ) ;
348354 // Clear the redirect user when signOut is called
349355 if ( this . redirectPersistenceManager || this . _popupRedirectResolver ) {
350356 await this . _setRedirectUser ( null ) ;
351357 }
352358
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 ) ;
354362 }
355363
356364 setPersistence ( persistence : Persistence ) : Promise < void > {
0 commit comments