fix(ios): use deleteToken in refreshToken to avoid race#189
Open
eljass wants to merge 1 commit into
Open
Conversation
The community master had two bugs in refreshToken on iOS: 1. Race condition: token() ran in parallel with deleteData(), not after it completed. The new token could be fetched before the old one was deleted, potentially returning the same token. 2. Used deleteData() which deletes all Messaging data, broader than necessary for token rotation. This fix: - Uses Messaging.messaging().deleteToken() — the Firebase-recommended API that only invalidates the current FCM token - Nests the token fetch inside the delete completion handler, ensuring proper sequencing (delete completes → then fetch new token) - Preserves Analytics/Crashlytics installation correlation (unlike the fork's Installations.delete approach) - Removes duplicate refreshToken registration in Plugin.m The Android implementation was already correct (properly nested deleteToken → getToken) and is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two issues in the iOS
refreshTokenimplementation:Race condition —
Messaging.messaging().token { ... }ran in parallel withdeleteData { ... }rather than after. The new token fetch could resolve before the delete completed and return the same token.Overly broad API —
deleteData()deletes all Messaging data;deleteToken()is the Firebase-recommended call for FCM token rotation.Also removes a duplicate
CAP_PLUGIN_METHOD(refreshToken, CAPPluginReturnPromise)registration inPlugin.m.Why
Reported in our app: rotating the FCM token sometimes returned the previous value, breaking server-side token replacement. The fix follows the Firebase iOS docs and matches the Android implementation in this plugin (which already nests
deleteToken→getTokencorrectly).Test plan
refreshToken()returns a different token fromgetToken()Installations.delete()which would invalidate it)Notes
No API change. No new dependencies. Android unchanged.