Skip to content

Commit 48825f4

Browse files
committed
Fix auth event uncancellable bug
1 parent 8e9aac2 commit 48825f4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,18 +591,31 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
591591
? nextOrObserver
592592
: nextOrObserver.next.bind(nextOrObserver);
593593

594+
let isUnsubscribed = false;
595+
594596
const promise = this._isInitialized
595597
? Promise.resolve()
596598
: this._initializationPromise;
597599
_assert(promise, this, AuthErrorCode.INTERNAL_ERROR);
598600
// The callback needs to be called asynchronously per the spec.
599601
// 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+
});
601606

602607
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+
};
604613
} else {
605-
return subscription.addObserver(nextOrObserver);
614+
const unsubscribe = subscription.addObserver(nextOrObserver);
615+
return () => {
616+
isUnsubscribed = true;
617+
unsubscribe();
618+
}
606619
}
607620
}
608621

0 commit comments

Comments
 (0)