|
77 | 77 |
|
78 | 78 | void FirebaseAppCheckCredentialsProvider::GetToken(
|
79 | 79 | 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 |
| - |
92 | 80 | std::weak_ptr<Contents> weak_contents = contents_;
|
93 | 81 | 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 | + |
94 | 91 | // Retrieve a cached or generate a new FAC Token. If forcingRefresh == YES
|
95 | 92 | // always generates a new token and updates the cache.
|
96 | 93 | [contents_->app_check getTokenForcingRefresh:force_refresh_
|
|
110 | 107 | // Fire initial event.
|
111 | 108 | change_listener(contents_->current_token);
|
112 | 109 | } else {
|
113 |
| - HARD_ASSERT(app_check_listener_handle_, "removed change_listener twice!"); |
114 | 110 | 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 | + } |
118 | 116 | }
|
119 | 117 |
|
120 | 118 | change_listener_ = change_listener;
|
|
0 commit comments