Skip to content

Commit bb8f37c

Browse files
authored
Do not invoke the App Check token listener for the same token string. (#5993)
* Do not invoke the App Check token listener for the same token string. * Fix formatting. * Address comments. * Create gold-hounds-begin.md * Use fewer bytes for log messages.
1 parent 50de44c commit bb8f37c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.changeset/gold-hounds-begin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Fixed a bug that caused Firestore streams to get restarted with the same App Check token.

packages/firestore/src/api/credentials.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,9 @@ export class FirebaseAppCheckTokenProvider
461461
* we can unregister it.
462462
*/
463463
private tokenListener!: AppCheckTokenListener;
464-
465464
private forceRefresh = false;
466-
467465
private appCheck: FirebaseAppCheckInternal | null = null;
466+
private latestAppCheckToken: string | null = null;
468467

469468
constructor(
470469
private appCheckProvider: Provider<AppCheckInternalComponentName>
@@ -482,7 +481,15 @@ export class FirebaseAppCheckTokenProvider
482481
`Error getting App Check token; using placeholder token instead. Error: ${tokenResult.error.message}`
483482
);
484483
}
485-
return changeListener(tokenResult.token);
484+
const tokenUpdated = tokenResult.token !== this.latestAppCheckToken;
485+
this.latestAppCheckToken = tokenResult.token;
486+
logDebug(
487+
'FirebaseAppCheckTokenProvider',
488+
`Received ${tokenUpdated ? 'new' : 'existing'} token.`
489+
);
490+
return tokenUpdated
491+
? changeListener(tokenResult.token)
492+
: Promise.resolve();
486493
};
487494

488495
this.tokenListener = (tokenResult: AppCheckTokenResult) => {
@@ -534,6 +541,7 @@ export class FirebaseAppCheckTokenProvider
534541
typeof tokenResult.token === 'string',
535542
'Invalid tokenResult returned from getToken():' + tokenResult
536543
);
544+
this.latestAppCheckToken = tokenResult.token;
537545
return new AppCheckToken(tokenResult.token);
538546
} else {
539547
return null;

0 commit comments

Comments
 (0)