Search code examples
push-notificationweb-push

When to delete Push subscription from server


Just started playing with push notifications and I managed to handle all the subscription process and I'm saving endpoints and keys on my db. My questions is, what strategy should I follow, if any, to delete old subcription details from the database?. So, if someone allowed notifications and they revoke the permission how do I know who did it to remove the details from the database?. Because if the user unsubscribes I'll just get a null subscription from pushManager.


Solution

  • For Pushpad we use these two strategies:

    • when a user revokes the permission the requests made using that endpoint will return 410 Gone and you should delete the endpoint
    • a developer can optionally trigger an unsubscribe with the Javascript SDK that will remove the endpoint from the server (this is useful for example to create a subscribe/unsubscribe button on the website)