Users and sign-out
Link devices to your users so you can send to a person, and keep that link right through sign-out, reinstalls and account deletion.
Sending to "userIds": ["u_123"] reaches every device where the app called Pushwren.setUserID("u_123").
Set the user after sign-in and at launch
Pushwren.setUserID("u_123")
Call it after sign-in, and at every launch while someone is signed in. A reinstalled app starts with no user on the server even if your sign-in survived in the Keychain; the call at launch links it again, and costs nothing when nothing changed. Setting the same user ID again sends nothing until the next launch, so calling it on every refresh is fine.
Use an opaque user ID, such as your database’s ID for the user, not an email address or a phone number.
Sign-out
Pushwren.clearUserID()
It goes out at once, even if a retry is waiting. Tags stay: remove the ones that belonged to the user with Pushwren.removeTags([...]).
Reinstalls
A reinstalled app keeps its device ID but starts with no user and no tags on the server. Set them again at launch.
Tags
Pushwren.addTags(["pro"])
Pushwren.removeTags(["trial"])
Send to "tags": ["pro"] to reach every device with any of the tags.
When a user deletes their account
let removed = await Pushwren.deleteDevice()
It removes the device record with its user and tags. The device registers again, as a new device with no user, the next time the app syncs. It returns false if Pushwren couldn’t be reached. Your server can also delete every device of a user with DELETE /v1/users/{userId}.
Making sure only your server can set a user
A modified app could call setUserID with someone else’s ID. Identity verification makes your server sign each user ID.