Home > OS >  Firebase Messaging topic unsubscribe : Do we need to unsubscribe explicitly if fcmToken changes
Firebase Messaging topic unsubscribe : Do we need to unsubscribe explicitly if fcmToken changes

Time:02-02

My flow is:

  • At the login store FCM token in firestore DB and also subscribe to 2 topics for notification
  • On change/refresh of fcmToken : again store it in DB (replace old fcmToken and keep current) and subscribe again to those 2 topics.
  • My doubt is do i need to unsubscribe old FCM token from those 2 topics ?

CodePudding user response:

The Firebase Cloud Messaging topic fan-out service, which handles the mapping from a topic to the associated FCM tokens, automatically detects invalid and expired tokens and removes them as needed. So while you can unsubscribe them yourself, it is not required to do so.

The approach FCM takes for this is similar to what you see in to this code sample from one of our repos. You won't need it when you only use topics, but if you ever decide to implement your own token registry you'll want to use that approach to prune that registry.

  • Related