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 @@ -591,18 +591,31 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
591
591
? nextOrObserver
592
592
: nextOrObserver . next . bind ( nextOrObserver ) ;
593
593
594
+ let isUnsubscribed = false ;
595
+
594
596
const promise = this . _isInitialized
595
597
? Promise . resolve ( )
596
598
: this . _initializationPromise ;
597
599
_assert ( promise , this , AuthErrorCode . INTERNAL_ERROR ) ;
598
600
// The callback needs to be called asynchronously per the spec.
599
601
// eslint-disable-next-line @typescript-eslint/no-floating-promises
600
- promise . then ( ( ) => cb ( this . currentUser ) ) ;
602
+ promise . then ( ( ) => {
603
+ if ( isUnsubscribed ) { return ; }
604
+ cb ( this . currentUser ) ;
605
+ } ) ;
601
606
602
607
if ( typeof nextOrObserver === 'function' ) {
603
- return subscription . addObserver ( nextOrObserver , error , completed ) ;
608
+ const unsubscribe = subscription . addObserver ( nextOrObserver , error , completed ) ;
609
+ return ( ) => {
610
+ isUnsubscribed = true ;
611
+ unsubscribe ( ) ;
612
+ } ;
604
613
} else {
605
- return subscription . addObserver ( nextOrObserver ) ;
614
+ const unsubscribe = subscription . addObserver ( nextOrObserver ) ;
615
+ return ( ) => {
616
+ isUnsubscribed = true ;
617
+ unsubscribe ( ) ;
618
+ }
606
619
}
607
620
}
608
621
You can’t perform that action at this time.
0 commit comments