# Don't remove all push subscriptions on logoff

**URL:** https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038
**Category:** Feature
**Tags:** push-notifications
**Created:** [November 21, 2019, 3:19am UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038 "2019-11-21T03:19:26Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![MojoK](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@MojoK](https://meta.discourse.org/u/MojoK)
#### Post date: [November 21, 2019, 3:19am UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/1 "2019-11-21T03:19:26Z")

</div>

> [@Automatically renew the push notifications subscription](https://meta.discourse.org/t/automatically-renew-the-push-notifications-subscription/125179/1):
>
> We have plenty of cases where the notifications [cease](https://meta.discourse.org/t/browser-push-notification-intervals/101380) to [work](https://meta.discourse.org/t/what-may-cause-the-live-notification-to-stop-working-for-a-forum/120068) all of sudden, and this may be one of the reasons why.

Also it seems like when a user logouts, all push subscriptions are deleted. So if a user is logged in on multiple devices (phone, browser, tablet) and logouts from one device/session, it prevents other devices from getting notifications as their push subscriptions are deleted.

I mention this as its related to knowing which subscription needs to be replaced during renewal, and which subscription should be deleted on logout.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [November 21, 2019, 3:39am UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/2 "2019-11-21T03:39:55Z")

</div>

Well I was just logged out of Meta today and after logging in I got a push notification for your post… Unless it’s only on the user initiated login code path 🤔

---

<div class="post-metadata">

### Author: ![MojoK](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@MojoK](https://meta.discourse.org/u/MojoK)
#### Post date: [November 21, 2019, 4:05am UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/3 "2019-11-21T04:05:25Z")

</div>

When a user comes back to the forum (or logs in), the browsers push subscriptions are sent again and are recreated. But if you logged out, they are deleted and no push notifications will be delivered until that user goes to the forum from that device.

This doesn’t contradict what you stated since you appear to be saying you got the push notification after logging in.

Code Reference:

> <https://github.com/discourse/discourse/blob/03d28342f87814e997407f6e7bf0309b02d942d2/config/initializers/100-push-notifications.rb#L29>

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [November 21, 2019, 2:30pm UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/4 "2019-11-21T14:30:33Z")

</div>

Oh so this is exactly what I suspected

> [@Falco](#):
>
> only on the user initiated logoff code path

Nice find! We gotta fix this for sure!

Problem is that currently we don’t store for which device a specific subscription exists for…

---

<div class="post-metadata">

### Author: ![MojoK](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@MojoK](https://meta.discourse.org/u/MojoK)
#### Post date: [November 21, 2019, 5:49pm UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/5 "2019-11-21T17:49:26Z")

</div>

The Push API does have a `unsubscribe` function to invalidate the push subscription:

> **[PushSubscription: unsubscribe() method - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription/unsubscribe)**
>
> The unsubscribe() method of the PushSubscription interface
> returns a Promise that resolves to a boolean value when the
> current subscription is successfully unsubscribed.

On logout, we would invoke this (client side) would render that subscription on the server as invalid without affecting any other subscriptions.

In fact, the client already has a `unsubscribePushNotification` function that does this in the “Live Notification” prefrences. Maybe the solution is to invoke this on logout client side if Live Notifications is enabled. Probably good practice to revoke the client side subscription keys instead of just deleting them from server.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [November 21, 2019, 7:45pm UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/6 "2019-11-21T19:45:11Z")

</div>

So the fix can be in two parts:

1. Delete the server side cleanup code
2. Add new code to unsubscribe on the client-side.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 15, 2026, 8:04pm UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/7 "2026-04-15T20:04:24Z")

</div>

Done in

[https://github.com/discourse/discourse/pull/39266](https://github.com/discourse/discourse/pull/39266)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 20, 2026, 11:00am UTC](https://meta.discourse.org/t/dont-remove-all-push-subscriptions-on-logoff/134038/8 "2026-04-20T11:00:11Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
