Reputation: 1876
I'm a beginner in fcm
and stuck in one issue. After getting reference from several source I'm able to implement it successfully. But now I'm trapped in a strange issue.
As fcm
creates unique tokens per device so notifications can be sent to that device using that unique token only . So, after the token is generated I'm saving that token into mongodb for that particular user and the notification is sent to that device without any problem.
Now let's assume a scenario : Let a and b be two users having different device so they'll have unique tokens in their mongodb documents
. Now if a will try to logging in into his account from b's device then how can I send notification to a's account in b's device as the mongo-document
of a containing token for a's device which can't be used for the current i.e b's device
Please do excuse me if my question is silly.
Upvotes: 2
Views: 1029
Reputation: 3520
You need to always make sure you update tokens when a user signs up or logs into a new device. If the user has give permission before, this shouldn't notify the user again and if not, user will be prompted to give permission and you can save the new token then.
It is usually good to keep the tokens in format of an array so you can send notifcation to all the tokens inside that array at any given time, i.e, all the devices that user is logged into.
Here's an example which you can see the token being saved in an array.
Upvotes: 3