Understanding push notification flow

Hi!

I’m currently implementing push notifications and I got firebase set up etc. All working great so far, I love it. But I’m also quite new to all this. I understand that the token is bound to the user’s device where I first assumed it should be tied to the user’s account. How do you deal with logging out from the app and using a different device? Here’s what I’m thinking and I’d like to know if I got this right (we’re using a java backend btw):

  • get token from expo and save it in the database for new user
  • when the user logs out delete the token for that user from the database (and remove from Expo?)
  • when the user logs back in/reinstalls app get a new token and store in the database

Also, if a user uses the app on multiple devices, should I store two tokens or use the same token for two devices? I have done some research but I can’t find a good answer to this. Some more insight would be much appreciated.

Thank you very much in advance!

I think I got it pretty much figured out (got some help from a friend). I’ll post the answer here for others struggling to get a grasp of the concept.

In my case I’m going for this: A device has 1 token at a time. When a user logs in, the backend must recieve that token (device) and assign it to the currently logged in user. A token can only have 1 user at a time but a user can have multiple tokens (devices). When someone else logs in on the same device, the token must move from the previous user to the new user.

I might update this when it’s fully implemented =)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.