Skip to content

Commit 6176fb1

Browse files
Remove assert that AppCheckListener is always registered (#8900)
1 parent dffe49c commit 6176fb1

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Firestore/core/src/credentials/firebase_app_check_credentials_provider_apple.mm

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,17 @@
7777

7878
void FirebaseAppCheckCredentialsProvider::GetToken(
7979
TokenListener<std::string> completion) {
80-
HARD_ASSERT(app_check_listener_handle_,
81-
"GetToken cannot be called after listener removed.");
82-
83-
void (^get_token_callback)(id<FIRAppCheckTokenResultInterop>) =
84-
^(id<FIRAppCheckTokenResultInterop> result) {
85-
if (result.error != nil) {
86-
LOG_WARN("AppCheck failed: '%s'",
87-
util::MakeString(result.error.localizedDescription));
88-
}
89-
completion(util::MakeString(result.token)); // Always return token
90-
};
91-
9280
std::weak_ptr<Contents> weak_contents = contents_;
9381
if (contents_->app_check) {
82+
void (^get_token_callback)(id<FIRAppCheckTokenResultInterop>) =
83+
^(id<FIRAppCheckTokenResultInterop> result) {
84+
if (result.error != nil) {
85+
LOG_WARN("AppCheck failed: '%s'",
86+
util::MakeString(result.error.localizedDescription));
87+
}
88+
completion(util::MakeString(result.token)); // Always return token
89+
};
90+
9491
// Retrieve a cached or generate a new FAC Token. If forcingRefresh == YES
9592
// always generates a new token and updates the cache.
9693
[contents_->app_check getTokenForcingRefresh:force_refresh_
@@ -110,11 +107,12 @@
110107
// Fire initial event.
111108
change_listener(contents_->current_token);
112109
} else {
113-
HARD_ASSERT(app_check_listener_handle_, "removed change_listener twice!");
114110
HARD_ASSERT(change_listener_, "change_listener removed without being set!");
115-
[[NSNotificationCenter defaultCenter]
116-
removeObserver:app_check_listener_handle_];
117-
app_check_listener_handle_ = nil;
111+
if (app_check_listener_handle_) {
112+
[[NSNotificationCenter defaultCenter]
113+
removeObserver:app_check_listener_handle_];
114+
app_check_listener_handle_ = nil;
115+
}
118116
}
119117

120118
change_listener_ = change_listener;

0 commit comments

Comments
 (0)