Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

FCM token changing over time, how to deduplicate?

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…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading