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 {
604
604
? nextOrObserver
605
605
: nextOrObserver . next . bind ( nextOrObserver ) ;
606
606
607
+ let isUnsubscribed = false ;
608
+
607
609
const promise = this . _isInitialized
608
610
? Promise . resolve ( )
609
611
: this . _initializationPromise ;
610
612
_assert ( promise , this , AuthErrorCode . INTERNAL_ERROR ) ;
611
613
// The callback needs to be called asynchronously per the spec.
612
614
// 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
+ } ) ;
614
619
615
620
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
+ } ;
617
626
} else {
618
- return subscription . addObserver ( nextOrObserver ) ;
627
+ const unsubscribe = subscription . addObserver ( nextOrObserver ) ;
628
+ return ( ) => {
629
+ isUnsubscribed = true ;
630
+ unsubscribe ( ) ;
631
+ }
619
632
}
620
633
}
621
634
You can’t perform that action at this time.
0 commit comments