Skip to content

Commit 2e45a15

Browse files
committed
Fix auth event uncancellable bug
1 parent 503ca1e commit 2e45a15

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
@@ -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

0 commit comments

Comments
 (0)