Skip to content

Commit e3d7408

Browse files
rsgowmanFeiyang1
authored andcommitted
Avoid auth triggers if we haven't yet received the initial user. (#2137)
* 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 * CHANGELOG update. * Fix to be more like android
1 parent fa3fc0f commit e3d7408

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
data from disk.
99
- [changed] Improved performance for queries with filters that only return a
1010
small subset of the documents in a collection.
11+
- [fixed] Fixed a race condition between authenticating and initializing
12+
Firestore that could result in initial writes to the database being dropped.
1113

1214
# 1.4.10
1315
- [changed] Transactions now perform exponential backoff before retrying.

packages/firestore/src/api/credentials.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
156156
}
157157
};
158158

159+
this.currentUser = this.getUser();
159160
this.tokenCounter = 0;
160161

161162
// Will fire at least once where we set this.currentUser
@@ -209,10 +210,8 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
209210
assert(!this.changeListener, 'Can only call setChangeListener() once.');
210211
this.changeListener = changeListener;
211212

212-
// Fire the initial event, but only if we received the initial user
213-
if (this.currentUser) {
214-
changeListener(this.currentUser);
215-
}
213+
// Fire the initial event
214+
changeListener(this.currentUser);
216215
}
217216

218217
removeChangeListener(): void {

0 commit comments

Comments
 (0)