Skip to content

Commit a026e3d

Browse files
Re-establish streams when App Check token expires. (#9233)
* Re-establish streams when App Check token expires. * Add comment about why we ignore notification before client initialization. * Add to CHANGELOG.md * Update Firestore/CHANGELOG.md Co-authored-by: Sebastian Schmidt <[email protected]> Co-authored-by: Sebastian Schmidt <[email protected]>
1 parent 3784deb commit a026e3d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Firestore/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Unreleased
2+
- [fixed] Fixed an AppCheck issue that caused Firestore listeners to stop
3+
working and receive a "Permission Denied" error. This issue only occurred for
4+
AppCheck users that set their expiration time to under an hour.
5+
16
# v8.11.0
27
- [fixed] Fixed an issue that can result in incomplete Query snapshots when an
38
app is backgrounded during query execution.

Firestore/core/src/core/firestore_client.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,23 @@ std::shared_ptr<FirestoreClient> FirestoreClient::Create(
145145
};
146146

147147
shared_client->app_check_credentials_provider_->SetCredentialChangeListener(
148-
[](std::string) {
149-
// Register an empty credentials change listener to activate token
150-
// refresh.
148+
[weak_client](const std::string&) {
149+
auto shared_client = weak_client.lock();
150+
if (!shared_client) return;
151+
// It is okay to ignore an App Check token change notification if
152+
// FirestoreClient::Initialize has not been invoked yet because
153+
// once initialization does occur, setting up new watch streams will use
154+
// the latest App Check token available.
155+
if (shared_client->credentials_initialized_) {
156+
shared_client->worker_queue_->Enqueue([shared_client] {
157+
LOG_DEBUG("App Check token Changed.");
158+
// This will ensure that once a new App Check token is retrieved,
159+
// streams are re-established using the new token.
160+
shared_client->remote_store_->HandleCredentialChange();
161+
});
162+
}
151163
});
164+
152165
shared_client->auth_credentials_provider_->SetCredentialChangeListener(
153166
credential_change_listener);
154167

0 commit comments

Comments
 (0)