I searched online but nobody bizarrely talks about it.
First of all, API doesn't seem to support several subscription contexts, it takes no arguments.
But that's not a huge issue because if one user has already given permissions, I can get the already existing subscription and reuse it/point it to second user too (use same url for both).
Here's where problems start. If one user is logged in (e.g token in LocalStorage), browser is closed and I send a notification which then wakes up Service Worker and runs my notification event code..
How do I know if I should show the notification or not? How do I know who's logged in? I have no access to LocalStorage in Service Worker, I have no idea who's logged in. Any other ways?
Android supports multiple users on a single Android device by separating user accounts and application data. For instance, parents may allow their children to use the family tablet, a family can share an automobile, or a critical response team might share a mobile device for on-call duty.
Add another account to a device On your Android phone or tablet, say "Hey Google, open Assistant settings." Or, go to Assistant settings. Make sure you're signed in to the additional account you want to use: Next to your email address, tap the Down arrow . If the account isn't listed, tap Add another account.
We tried many different solutions and finally we opted for this approach: an endpoint is associated at most to one user ID.
When you send the endpoint to your server for storage, you also send the current user ID, which will be attached to that endpoint (subscription) in your database.
When the user logs out, you make a Javascript call from that browser that removes the user ID from the subscription in your database.
When you need to target a user you query the database to find the devices currently associated to that user.
You cannot have multiple users logged in on your website at the same time, so it doesn't make sense to have multiple users associated to a browser endpoint at the same time. If two users, at different times, share the same browser, you just update the user ID for that subscription when the user logs out (remove user ID) or logs in (set user ID).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With