I'm wondering how to ensure security within some scenarios.
Let's say you save your messaging tokens for each device to Firestore as a subcollection 'tokens' under each user, like so: https://youtu.be/2TSm2YGBT1s?t=382
You want to send a message to a user's devices, so you loop through the tokens and send a message to each one of them.
But what if you have previously logged in on someone else's computer or phone? Now the other computer is saved under tokens and if you send a message, it goes to another person's device, which would be:
- A security flaw if your payload contains private data (like a chat message)
- Annoying for the person whose device is being targeted.
- Wasteful: maybe some of the tokens are old and the device doesn't exist anymore.
How can I build a messaging system that works on users multiple devices that doesn't have these flaws?