File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
packages/auth/src/core/auth Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -604,18 +604,31 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
604604 ? nextOrObserver
605605 : nextOrObserver . next . bind ( nextOrObserver ) ;
606606
607+ let isUnsubscribed = false ;
608+
607609 const promise = this . _isInitialized
608610 ? Promise . resolve ( )
609611 : this . _initializationPromise ;
610612 _assert ( promise , this , AuthErrorCode . INTERNAL_ERROR ) ;
611613 // The callback needs to be called asynchronously per the spec.
612614 // eslint-disable-next-line @typescript-eslint/no-floating-promises
613- promise . then ( ( ) => cb ( this . currentUser ) ) ;
615+ promise . then ( ( ) => {
616+ if ( isUnsubscribed ) { return ; }
617+ cb ( this . currentUser ) ;
618+ } ) ;
614619
615620 if ( typeof nextOrObserver === 'function' ) {
616- return subscription . addObserver ( nextOrObserver , error , completed ) ;
621+ const unsubscribe = subscription . addObserver ( nextOrObserver , error , completed ) ;
622+ return ( ) => {
623+ isUnsubscribed = true ;
624+ unsubscribe ( ) ;
625+ } ;
617626 } else {
618- return subscription . addObserver ( nextOrObserver ) ;
627+ const unsubscribe = subscription . addObserver ( nextOrObserver ) ;
628+ return ( ) => {
629+ isUnsubscribed = true ;
630+ unsubscribe ( ) ;
631+ }
619632 }
620633 }
621634
You can’t perform that action at this time.
0 commit comments