Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Push Notifications endpoint + user identification

I have plan to integrate Push Notifications for Chrome (Push API and Notification API).

After successful subscription Chrome server send to client some special token ("endpoint") which you can use to identify the client and to send any push messages.

From the doc:

The endpoint should be saved on your server for each user, since you’ll need them to send push messages at a later date.

I have few questions:

  1. How you manage "endpoint" on your server side? Would you send this "endpoint" after successful subscription to your server by AJAX and save into DB. Or you save it to the cookies and after that save it on the server after login/registration request.
  2. I wonder, how you connect "endpoint" with real user? User can open your site, click "Allow" to show push notification, but he doesn't have the session cookie, so you can't identify this "endpoint" with real user on that time.
  3. Does this "endpoint" have some TTL?
like image 781
vaxXxa Avatar asked Sep 26 '22 02:09

vaxXxa


1 Answers

  1. Yes, you can send it to the server and the server can store it in the DB. See for example [1].
  2. It depends on your application. Sometimes you don't need to link the endpoint to a user. If you do, then simply the endpoint can be a property of your user object on the server. If a user registers for push notifications before logging-in, then you have no way to tell that that endpoint is related to that user. When the user logs in you can send the updated info to the server.
  3. Yes, the endpoint can expire (see [2]). The 'subscriptionchange' event will be fired when this happens, service workers can listen to this event and send the updated info to the server (again, you can see [1] as an example, or [3]).
like image 148
Marco Castelluccio Avatar answered Oct 03 '22 02:10

Marco Castelluccio