Eneris / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
16 stars 16 forks source link

New token every App Launch. #4

Closed bjsvedin closed 2 years ago

bjsvedin commented 2 years ago

I have implemented this library over the original to try and fix a bug where notifications stop working after some time. I am testing that now, but I noticed another item that I would like resolved.

I get a new FCM token every single time I open up my electron application. Using a development build, or a production build, every time the application is closed all the way, then relaunched, the token that I get will be a new token. In every other use for FCM that I have implemented, the token will remain the same between launched unless a manual reset was done, or the app uninstalled and reinstalled. I have not implemented any resets in my code.

This is an issue because I track these, and I view them later for testing and general data gathering, but a new token every time will clutter my data.

I have looked into the library as best i could to determine if I am missing something in the setup/configuration, but I have not found anything I needed to do.

If you need anything from me to help resolve this let me know, I will get it for you.

Eneris commented 2 years ago

Hi. Thanks for reaching out. You have to listen on credentials changes with instance.onCredentialsChanged and save them in your own storage. Then during the next launch, you need to supply them as property credentials to new PushReceiver

Edit: Let me know if you need more detailed example :)

Eneris commented 2 years ago

Basically, any time onCredentialsChanged gets called, you save the result somewhere and supply them to constructor next time you run it as "initial data". Otherwise it won't have it and creates new one.

bjsvedin commented 2 years ago

I was able to make it work, thank you. I looked back at other implementations and I can see where they did the same thing, but I missed it before.