Skip to content

Fix auth state change issues after refresh #4200

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 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions packages-exp/auth-exp/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export class AuthImpl implements Auth, _FirebaseService {
readonly name: string;

// Tracks the last notified UID for state change listeners to prevent
// repeated calls to the callbacks
private lastNotifiedUid: string | undefined = undefined;
// repeated calls to the callbacks. Undefined means it's never been
// called, whereas null means it's been called with a signed out user
private lastNotifiedUid: string | null | undefined = undefined;

languageCode: string | null = null;
tenantId: string | null = null;
Expand Down Expand Up @@ -474,8 +475,9 @@ export class AuthImpl implements Auth, _FirebaseService {

this.idTokenSubscription.next(this.currentUser);

if (this.lastNotifiedUid !== this.currentUser?.uid) {
this.lastNotifiedUid = this.currentUser?.uid;
const currentUid = this.currentUser?.uid ?? null;
if (this.lastNotifiedUid !== currentUid) {
this.lastNotifiedUid = currentUid;
this.authStateSubscription.next(this.currentUser);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/auth-types-exp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export interface Auth {
* @param completed - callback triggered when observer is removed.
*/
onAuthStateChanged(
nextOrObserver: NextOrObserver<User>,
nextOrObserver: NextOrObserver<User | null>,
error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe;
Expand All @@ -282,7 +282,7 @@ export interface Auth {
* @param completed - callback triggered when observer is removed.
*/
onIdTokenChanged(
nextOrObserver: NextOrObserver<User>,
nextOrObserver: NextOrObserver<User | null>,
error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe;
Expand Down