Skip to content

Commit 5dac8b3

Browse files
authored
[Auth] Fix auth event uncancellable bug (#7498)
* Fix auth event uncancellable bug * add changeset file * includes issue number on changesets * yarn format
1 parent 89fb9fd commit 5dac8b3

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

.changeset/mean-candles-approve.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Fix auth event uncancellable bug #7383

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -638,18 +638,37 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
638638
? nextOrObserver
639639
: nextOrObserver.next.bind(nextOrObserver);
640640

641+
let isUnsubscribed = false;
642+
641643
const promise = this._isInitialized
642644
? Promise.resolve()
643645
: this._initializationPromise;
644646
_assert(promise, this, AuthErrorCode.INTERNAL_ERROR);
645647
// The callback needs to be called asynchronously per the spec.
646648
// eslint-disable-next-line @typescript-eslint/no-floating-promises
647-
promise.then(() => cb(this.currentUser));
649+
promise.then(() => {
650+
if (isUnsubscribed) {
651+
return;
652+
}
653+
cb(this.currentUser);
654+
});
648655

649656
if (typeof nextOrObserver === 'function') {
650-
return subscription.addObserver(nextOrObserver, error, completed);
657+
const unsubscribe = subscription.addObserver(
658+
nextOrObserver,
659+
error,
660+
completed
661+
);
662+
return () => {
663+
isUnsubscribed = true;
664+
unsubscribe();
665+
};
651666
} else {
652-
return subscription.addObserver(nextOrObserver);
667+
const unsubscribe = subscription.addObserver(nextOrObserver);
668+
return () => {
669+
isUnsubscribed = true;
670+
unsubscribe();
671+
};
653672
}
654673
}
655674

0 commit comments

Comments
 (0)