firebase-ios-sdk: Messaging: `deleteToken` no longer deletes token correctly

Step 0: Are you in the right place?

  • For issues or feature requests related to the code in this repository file a Github issue.
    • If this is a feature request please use the Feature Request template.
  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general (non-iOS) Firebase discussion, use the firebase-talk google group.
  • For backend issues, console issues, and other non-SDK help that does not fall under one of the above categories, reach out to Firebase Support.
  • Once you’ve read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 12.5
  • Firebase SDK version: 8.5.0
  • Installation method: CocoaPods (select one)
  • Firebase Component: Messaging (Auth, Core, Database, Firestore, Messaging, Storage, etc)

[REQUIRED] Step 2: Describe the problem

FlutterFire: Issue: https://github.com/FirebaseExtended/flutterfire/issues/6766 RNFB: Issue https://github.com/invertase/react-native-firebase/issues/5570 P/R https://github.com/invertase/react-native-firebase/pull/5571

Steps to reproduce:

Call deleteTokenWithCompletion and inspect the token from tokenWithCompletion and see that it has not changed and is still valid.

From debugging, I can see that when the installations id is refreshed via installations.deleteWithCompletion, the token will always refresh when calling messaging.deleteTokenWithCompletion

This behaviour can be replicated both in FlutterFire and RNFB. My question is what is the correct solution/method to refresh an FCM token?

I’ve looked through the changelog and the documentation, and it’s still not 100% clear to me on how the installations id should be managed in relation to the FCM token.

Any help or guidance on this would be greatly appreciated.

Relevant Code:

By changing the following code, additional requests to deleteTokenWithCompletion will refresh the token: From:

[[FIRMessaging messaging] deleteTokenWithCompletion:^(NSError *_Nullable error) {
    if (error) {
      [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
    } else {
      resolve([NSNull null]);
    }
  }];

To:

[[FIRInstallations installations] deleteWithCompletion:^(NSError * _Nullable error) {
    if (error) {
      [RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
    } else {
      resolve([NSNull null]);
    }
  }];

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 19 (12 by maintainers)

Most upvoted comments

We are able to reproduce, I’m reaching out to our team for further investigation.

Thanks @helenaford and @mikehardy . I suspected that would be the expected use case.

I’d recommend you use the “deleting the installation id” flow that @helenaford posted above for that purpose.

I’d love to know if that flow doesn’t address your use case. Please feel free to reply back with any concerns or other use cases you might think of where you’d want to use deleteToken.

Personally, I’d like us to reconsider if it makes sense at all to have this deleteToken api. I think it adds a lot of confusion for the developer and seems to be adding unnecessary complexity to the API and the system.

@mikehardy yes, you only have to delete the installations token once, and then it will be ok again. And, yeah it’s not about old installations as I can reliably reproduce this issue by deleting the app, and reinstalling it - it resets the state back to the deleteToken not invalidating the token

I actually think it could be todo with the timing of when the Firebase App instance is initialized as I tried deleting the installations id in AppDelegate.m as the app is launching after:

    if ([FIRApp defaultApp] == nil) {
        [FIRApp configure];
    }
    
    // try to delete the installations token here
    [[FIRInstallations installations] deleteWithCompletion.....

with no luck sometimes. So maybe there’s a race condition? But it’s very confusing because the initial FCM token that is generated works - messages can be sent to the device via firebase-admin.

In terms of the side-effects of deleting the installations id, I was worried about the same thing. I can confirm it doesn’t affect the auth token, but not sure about thein-app-messaging token. I’d guess it would change too. I don’t see the harm if it did change, also I think most use-cases of deleting a token on the client are when a user wants to log out or delete their account.

@mikehardy I think the communication was misunderstood. What I meant is when you delete installations and get a new installation ID and new FCM token, then everything should function as expected. I was under the impression this was what you were asking. This helps you to resolve the issue and reset the state to back to normal.

If you deleted the installations and not getting a new installations ID and a FCM token, backend does a GDPR-compliant deletion and you should not expect anything is functional because the info has been wiped clean.

Yes. To enable debug logging set the following application argument: -FIRDebugEnabled (see http://goo.gl/RfcP7r)

@mikehardy the token is only used by Messaging, in-app-messaging does NOT use token and only the installations ID, and even if you delete the installation ID, the new one should function as expected for in-app-messaging continue on. So you should be fine.

This is introduced with the big refactor in an effort to remove instanceID dependency in I/O release v8.0.0