Skip to content

[Auth] Fix auth event uncancellable bug #7498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-candles-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Fix auth event uncancellable bug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: include reference to #7383

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added issue number

19 changes: 16 additions & 3 deletions packages/auth/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,31 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
? nextOrObserver
: nextOrObserver.next.bind(nextOrObserver);

let isUnsubscribed = false;

const promise = this._isInitialized
? Promise.resolve()
: this._initializationPromise;
_assert(promise, this, AuthErrorCode.INTERNAL_ERROR);
// The callback needs to be called asynchronously per the spec.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
promise.then(() => cb(this.currentUser));
promise.then(() => {
if (isUnsubscribed) { return; }
cb(this.currentUser);
});

if (typeof nextOrObserver === 'function') {
return subscription.addObserver(nextOrObserver, error, completed);
const unsubscribe = subscription.addObserver(nextOrObserver, error, completed);
return () => {
isUnsubscribed = true;
unsubscribe();
};
} else {
return subscription.addObserver(nextOrObserver);
const unsubscribe = subscription.addObserver(nextOrObserver);
return () => {
isUnsubscribed = true;
unsubscribe();
}
}
}

Expand Down