How to handle multiple users on one device



Let’s say I have user A and user B that both use my website. They are using the same computer. How can I be sure user A will not receive user B’s notifications when he is the one using the website?

One solution would be to send a user id alongside the notification and make sure when it is received that the logged user is the same as the recipient. But the notification event is already processing by WonderPush SDK service worker, therefore I don’t know how I can do the filtering. Is there a way to handle this with your SDK?


Hi Victor,

Our approach to this issue is precisely to give a userId when initializing the WonderPush SDK, as described in the docs in the advanced note of the integration section.

    webKey: 'YOUR_WEBKEY', // from the previous step
    userId: 'foobar',      // optional user id. Use null (the default) for unlogged users

Only one user is logged at a time globally on the browser. (Note: Using a different user profile in your browser is like running multiple separate browsers each on a single unique device, all on the same computer.) Whenever a new userId is used, be it null or not, the push token will be moved from the old installation of the old userId, to the installation for the new userId.
So the old installation is no longer reachable and the problem you mention is solved server-side without any work on your side.


Oh yeah right, I forgot you had this parameter available. Thanks !

But let’s say I really want to use installation id for sending notifications. If I associate a userId to this installation id using your management API and I give the userId when initializing the WonderPush SDK, would the SDK sort the notification to make sure the userId associated to the notification is the same as the one used to initialized the SDK?