When you say 'user' do you mean that your app can have different users log in and out?
To handle this, you can set up a table to map user_id
to push_token
and device_id
. You should also add an enabled
flag to this map - which means the user is currently logged in on that device.
Conceptually, while a device has only one push token, it may have many users, and a user may have many devices.
When a user signs into your app on a device you send user_id
, push_token
and device_id
and set enabled=TRUE
in your table. If this user/device combo never existed, add to your table.
When a user signs out of your app on a device you send user_id
and device_id
and set enabled=FALSE
in your table.
When an event occurs that would trigger a push to user with user_id
then you can look up what push_tokens
are associated to that user_id
and enabled=TRUE
. Then you can simply push to those tokens.