Skip to content

Commit 04f2e24

Browse files
authored
Fix auth state change issues (#4200)
1 parent e1649b4 commit 04f2e24

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ export class AuthImpl implements Auth, _FirebaseService {
8282
readonly name: string;
8383

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

8889
languageCode: string | null = null;
8990
tenantId: string | null = null;
@@ -474,8 +475,9 @@ export class AuthImpl implements Auth, _FirebaseService {
474475

475476
this.idTokenSubscription.next(this.currentUser);
476477

477-
if (this.lastNotifiedUid !== this.currentUser?.uid) {
478-
this.lastNotifiedUid = this.currentUser?.uid;
478+
const currentUid = this.currentUser?.uid ?? null;
479+
if (this.lastNotifiedUid !== currentUid) {
480+
this.lastNotifiedUid = currentUid;
479481
this.authStateSubscription.next(this.currentUser);
480482
}
481483
}

packages-exp/auth-types-exp/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export interface Auth {
267267
* @param completed - callback triggered when observer is removed.
268268
*/
269269
onAuthStateChanged(
270-
nextOrObserver: NextOrObserver<User>,
270+
nextOrObserver: NextOrObserver<User | null>,
271271
error?: ErrorFn,
272272
completed?: CompleteFn
273273
): Unsubscribe;
@@ -282,7 +282,7 @@ export interface Auth {
282282
* @param completed - callback triggered when observer is removed.
283283
*/
284284
onIdTokenChanged(
285-
nextOrObserver: NextOrObserver<User>,
285+
nextOrObserver: NextOrObserver<User | null>,
286286
error?: ErrorFn,
287287
completed?: CompleteFn
288288
): Unsubscribe;

0 commit comments

Comments
 (0)