Skip to content

Commit

Permalink
Avoid auth triggers if we haven't yet received the initial user.
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
rsgowman committed Sep 3, 2019
1 parent 611cc9d commit bb3723a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {

/** Tracks the current User. */
private currentUser: User = User.UNAUTHENTICATED;
private receivedInitialUser: boolean = false;

/**
* Counter used to detect if the token changed while a getToken request was
Expand All @@ -151,6 +152,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
this.tokenListener = () => {
this.tokenCounter++;
this.currentUser = this.getUser();
this.receivedInitialUser = true;
if (this.changeListener) {
this.changeListener(this.currentUser);
}
Expand Down Expand Up @@ -210,7 +212,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
this.changeListener = changeListener;

// Fire the initial event, but only if we received the initial user
if (this.currentUser) {
if (this.receivedInitialUser) {
changeListener(this.currentUser);
}
}
Expand Down

0 comments on commit bb3723a

Please sign in to comment.