Search code examples
push-notificationfirebase-cloud-messagingweb-push

How to update token when a user revokes permission for web push


I am new to web push. I have successfully implemented the code to request permission and receive notifications. I am wondering how I can catch the event when notification is denied after the user had granted the permission. ie: if the user revokes the permission after granting it, how can I catch that deny event (and even the re-granted event) in the service worker or js script and update my DB accordingly?


Solution

  • Is this needed? If the user revokes the permission, the push subscription will be invalid and can be removed or disable on your backend. If they renew the push subscription it'll be like a new browser being setup by the user.

    If you really need to track it, you could save the last state to indexdb (or local storage) and then detect the change in permission on the next visit.