Skip to content

Commit 44b5251

Browse files
Invoke RemoteStore's credential change listener even when user didn't change (#4189)
1 parent 566a62d commit 44b5251

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

.changeset/wicked-actors-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Fixes an issue that prevented the SDK from automatically retrieving custom User claims.

packages/firestore/src/core/firestore_client.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ export class FirestoreClient {
118118
) {
119119
this.credentials.setChangeListener(user => {
120120
logDebug(LOG_TAG, 'Received user=', user.uid);
121-
if (!this.user.isEqual(user)) {
122-
this.user = user;
123-
this.credentialListener(user);
124-
}
121+
this.user = user;
122+
this.credentialListener(user);
125123
this.receivedInitialUser.resolve();
126124
});
127125
}
@@ -199,11 +197,15 @@ export async function setOfflineComponentProvider(
199197
const configuration = await client.getConfiguration();
200198
await offlineComponentProvider.initialize(configuration);
201199

202-
client.setCredentialChangeListener(user =>
203-
client.asyncQueue.enqueueRetryable(async () => {
204-
await handleUserChange(offlineComponentProvider.localStore, user);
205-
})
206-
);
200+
let currentUser = configuration.initialUser;
201+
client.setCredentialChangeListener(user => {
202+
if (!currentUser.isEqual(user)) {
203+
currentUser = user;
204+
client.asyncQueue.enqueueRetryable(async () => {
205+
await handleUserChange(offlineComponentProvider.localStore, user);
206+
});
207+
}
208+
});
207209

208210
// When a user calls clearPersistence() in one client, all other clients
209211
// need to be terminated to allow the delete to succeed.

0 commit comments

Comments
 (0)