a7ul / web-push-demo

A blog demo to showcase how push notification works in web
https://blog.atulr.com/web-notifications
98 stars 56 forks source link

[QUESTION] How to remove subscription from the DB? #3

Open subashdbc opened 5 years ago

subashdbc commented 5 years ago

Hi, How do you remove the subscription details from the DB when Service worker being uninstalled? Can you suggest?

a7ul commented 5 years ago

Not sure what the context is, but ideally you could just update your subscription on db whenever a new one is issued. Do you really need to remove it from db ?

subashdbc commented 5 years ago

How do we know to which subscription it has to be updated in DB? Let's say I have logged in to the chrome on desktop and as well as logged in the mobile device, in this situation, we have stored 2 subscriptions right?

In this case, how can we know that it is from the mobile endpoint or chrome endpoint? Correct me if I am wrong? for now, I store only Auth, Endpoint, P256DH on DB. Do we need to store user_id or more_info also?

Please help me to clarify and guide me in the right way

Thanks in advance

a7ul commented 5 years ago

If you have a user_id - i would say link your user_id to the push tokens - that way you could target notifications to a particular customer.

If you cant have a user_id - You can maybe store a unique id on the device storage itself and use that to update ur push tokens whenever they change.

subashdbc commented 5 years ago

Thanks for the reply :) I got some inputs now.

Just a question let's say if the same user connects

  1. From Chrome (on desktop)
  2. From Mobile browser
  3. From some other machine, in this case, it is enough that we store only 1 subscription and keep updating the subscription details in the Database for that particular user?

Thanks in advance!

a7ul commented 5 years ago

Depends on what you are looking for/your requirements. If you want the push notification to go to all three devices you would store all of them if not just store the latest one.

subashdbc commented 5 years ago

Thanks for the suggestions :). If any I will reach out here