From 9d7ccba3608bce196db26b78f663f8cd1cde98da Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 10 Dec 2020 10:08:46 -0700 Subject: [PATCH 1/2] Invoke RemoteStore's credential change listener even when user didn't change --- common/api-review/firestore-exp.api.md | 5 ++--- common/api-review/firestore-lite.api.md | 4 +++- .../firestore/src/core/firestore_client.ts | 20 ++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/common/api-review/firestore-exp.api.md b/common/api-review/firestore-exp.api.md index 397d8732654..0ad651355a4 100644 --- a/common/api-review/firestore-exp.api.md +++ b/common/api-review/firestore-exp.api.md @@ -11,7 +11,6 @@ import { _FirebaseService } from '@firebase/app-types-exp'; import { LogLevelString as LogLevel } from '@firebase/logger'; import { Provider } from '@firebase/component'; import { SetOptions as SetOptions_2 } from '@firebase/firestore-types'; -import { SnapshotMetadata as SnapshotMetadata_2 } from '@firebase/firestore-types'; // @public export function addDoc(reference: CollectionReference, data: T): Promise>; @@ -440,11 +439,11 @@ export interface SnapshotListenOptions { } // @public -export class SnapshotMetadata implements SnapshotMetadata_2 { +export class SnapshotMetadata { constructor(hasPendingWrites: boolean, fromCache: boolean); readonly fromCache: boolean; readonly hasPendingWrites: boolean; - isEqual(other: SnapshotMetadata_2): boolean; + isEqual(other: SnapshotMetadata): boolean; } // @public diff --git a/common/api-review/firestore-lite.api.md b/common/api-review/firestore-lite.api.md index 96b285fc6c1..20f820e1b71 100644 --- a/common/api-review/firestore-lite.api.md +++ b/common/api-review/firestore-lite.api.md @@ -168,8 +168,10 @@ export abstract class FieldValue { abstract _toFieldTransform(context: ParseContext): FieldTransform | null; } +// Warning: (ae-forgotten-export) The symbol "FirestoreService" needs to be exported by the entry point index.d.ts +// // @public -export class FirebaseFirestore implements _FirebaseService { +export class FirebaseFirestore implements FirestoreService { constructor(databaseIdOrApp: DatabaseId | FirebaseApp, authProvider: Provider); get app(): FirebaseApp; // Warning: (ae-forgotten-export) The symbol "CredentialsProvider" needs to be exported by the entry point index.d.ts diff --git a/packages/firestore/src/core/firestore_client.ts b/packages/firestore/src/core/firestore_client.ts index 2445b351113..9a764979f81 100644 --- a/packages/firestore/src/core/firestore_client.ts +++ b/packages/firestore/src/core/firestore_client.ts @@ -118,10 +118,8 @@ export class FirestoreClient { ) { this.credentials.setChangeListener(user => { logDebug(LOG_TAG, 'Received user=', user.uid); - if (!this.user.isEqual(user)) { - this.user = user; - this.credentialListener(user); - } + this.user = user; + this.credentialListener(user); this.receivedInitialUser.resolve(); }); } @@ -199,11 +197,15 @@ export async function setOfflineComponentProvider( const configuration = await client.getConfiguration(); await offlineComponentProvider.initialize(configuration); - client.setCredentialChangeListener(user => - client.asyncQueue.enqueueRetryable(async () => { - await handleUserChange(offlineComponentProvider.localStore, user); - }) - ); + let currentUser = configuration.initialUser; + client.setCredentialChangeListener(user => { + if (!currentUser.isEqual(user)) { + currentUser = user; + client.asyncQueue.enqueueRetryable(async () => { + await handleUserChange(offlineComponentProvider.localStore, user); + }); + } + }); // When a user calls clearPersistence() in one client, all other clients // need to be terminated to allow the delete to succeed. From 0c73ef1278c099a48b753ee30a5239cf9221faf5 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 10 Dec 2020 10:30:37 -0700 Subject: [PATCH 2/2] Create wicked-actors-clap.md --- .changeset/wicked-actors-clap.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wicked-actors-clap.md diff --git a/.changeset/wicked-actors-clap.md b/.changeset/wicked-actors-clap.md new file mode 100644 index 00000000000..effcbe49678 --- /dev/null +++ b/.changeset/wicked-actors-clap.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": patch +--- + +Fixes an issue that prevented the SDK from automatically retrieving custom User claims.