I would be curious to know how the application code should handle the revoking of Notification permission token in conjunction with Firebase Cloud Messaging (FCM). The question is partially similar to this post/answer although their case does not include FCM.
So we have the following scenario:
The app does not require users to log in (hence the tokens we store in a database are anonymous, not associated with any
uid
)The app offers a set of opt-in/opt-out buttons to grant and revoke Notification permission.
The app collects the tokens in the database, for later use by
sendToDevice(tokens, notifcation)
in firebase functions.The app persists the token after the token has been issued (
getToken
) or refreshed (onTokenRefresh
) by utilizinglocalStorage
in order to later supply it todeleteToken(token)
and also to indicate in UI the current status of notification subscription.Now, user chooses to revoke permission that had once been granted - if they do so cleanly (via the opt-out button), the
deleteToken(token)
method is invoked and the appropriate local storage item is cleared. Everything should be in sync and FCM will no longer send to this user.Question What if user clears all permissions or local storage in a more administrative/bulk way, on global browser scope. The things get then out of sync. The token disappears from the browser and UI is going to show opted out, but the token has not been deleted from database, therefore it is still valid and the user is going to keep getting the notifications. The result of the sending will not contain any error for this user, so we will not be able to recognize the situation and remove the token.
What is the most common practice here? Are anonymous notifications discouraged? Am I missing anything in my understanding of Notification and FCM?