Reputation: 1563
When registering a browser in FCM, I get a unique token that I register in my database to send notifications. I have noticed that this token changes if the user unregisters and registers again.
Example:
f991KszkPdZEwIblAIh1bx:APA91bH-AL26ApKN8ucTS3s0Mi9wDqKHDXVMFaDaBzwIeXZTSw2qfMuWf68qaEEYbsJqvgMiQEyE_6bgMyxMiMh2iBvH_uSlADG6ljZcoSV6_JdLuKN7EpSrVJil43MDd...etc...
f991KszkPdZEwIblAIh1bx:APA91bE2UQ0FkJGOxqTXTviPv051sLAlGkakKon-LaNgRFd0bkdm1AFY5yKRNg0Ft9eeHzu1bVWU7JUuHz4EsOTVcu4cxuxIP8k871FRAb_CZNen0NiA6ia6pJFJNowbJ0W...etc... Those tokens are for exactly the same browser and domain but I unregistered and then registered again to end up with a different token.
How can I remove the entries to avoid sending two messages to the same browser? I see that the 29 first characters are the same, should I look for the first 29 chars for each registration?
Thanks
Laurent
Upvotes: 0
Views: 610
Reputation: 599091
Firebase ensures that each app/device combination always has at most one active token. Once you get a new token for the app instance, the old token immediately stops working.
To ensure your token registry doesn't get an ever larger number of expired tokens, you can check the result of sending a message to the token, and removing the token when you get back messaging/invalid-registration-token
or messaging/registration-token-not-registered
responses. For an example of this, see the Cloud Functions example here.
Upvotes: 1