Skip to content

Commit bb3723a

Browse files
committed
Avoid auth triggers if we haven't yet received the initial user.
#2078 altered the initial state of currentUser from undefined to not undefined, which caused the if statement to unconditionally evaluate to true. This results in a race condition that could cause some initial writes to the database to be dropped. Fixes #2135
1 parent 611cc9d commit bb3723a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/firestore/src/api/credentials.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
135135

136136
/** Tracks the current User. */
137137
private currentUser: User = User.UNAUTHENTICATED;
138+
private receivedInitialUser: boolean = false;
138139

139140
/**
140141
* Counter used to detect if the token changed while a getToken request was
@@ -151,6 +152,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
151152
this.tokenListener = () => {
152153
this.tokenCounter++;
153154
this.currentUser = this.getUser();
155+
this.receivedInitialUser = true;
154156
if (this.changeListener) {
155157
this.changeListener(this.currentUser);
156158
}
@@ -210,7 +212,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
210212
this.changeListener = changeListener;
211213

212214
// Fire the initial event, but only if we received the initial user
213-
if (this.currentUser) {
215+
if (this.receivedInitialUser) {
214216
changeListener(this.currentUser);
215217
}
216218
}

0 commit comments

Comments
 (0)