Don't remove all push subscriptions on logoff

AI-generated summary

The discussion addresses a critical issue where logging out of a Discourse forum deletes all push subscriptions, preventing notifications from reaching other active devices. MojoK highlights that while subscriptions are recreated upon login, a logout from one session invalidates subscriptions globally. Falco initially suspected this behavior might be limited to specific code paths but confirmed it occurs universally upon logout.

To resolve this, MojoK proposes utilizing the browser’s Push API unsubscribe function on the client side. This approach would invalidate only the specific subscription for the device logging out, preserving others, rather than deleting all server-side records. The suggested fix involves two steps: removing the existing server-side cleanup code and implementing client-side unsubscription logic during logout.

Falco agrees with this two-part solution, noting that the server currently lacks tracking for specific device subscriptions. The proposed changes were successfully implemented and merged in pull request #39266.

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.

6 Likes

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 :thinking:

6 Likes

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:

6 Likes

Oh so this is exactly what I suspected

Nice find! We gotta fix this for sure!

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

8 Likes

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

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.

2 Likes

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.
5 Likes

Done in

https://github.com/discourse/discourse/pull/39266

1 Like

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