How can you manage push notifications when a user uses multiple accounts on the same browser? What can you do if multiple users use the same device / browser?
- User1 logs in to your website
- Then User1 logs out and logs in as User2 using the same browser.
What happens to web push notifications in this case?
The best strategy is to keep track of which user is currently logged in and deliver only the notifications for that user.
In particular every time that a user logs in you need to:
- get the push subscription from the browser
- send it to your backend and update the user ID associated to it (in the database).
If you use Pushpad for web push notifications it’s even easier to change the user associated to the current browser. When User2 logs in to your website (account change) you can simply call:
pushpad('uid', 'User2', 'UID_SIGNATURE_FOR_SECURITY');
In this way the push subscription is now associated to User2 and the current browser will only receive the notifications for User2. You can also see more examples about log in / log out.