From 51c66a791366eec6debbffb9c78a695ac747f55b Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Mon, 8 Dec 2025 22:05:53 +0100 Subject: [PATCH] fix(webpush): only remove the current browser's subscription Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- .../UserNotificationsWebPush/index.tsx | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx index 3381f3c13..8ebc53c5d 100644 --- a/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx +++ b/src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx @@ -117,21 +117,17 @@ const UserWebPushSettings = () => { localStorage.setItem('pushNotificationsEnabled', 'false'); setWebPushEnabled(false); + // Only delete the current browser's subscription, not all devices const endpointToDelete = unsubscribedEndpoint || subEndpoint || endpoint; - const endpointsToDelete: string[] = endpointToDelete - ? [endpointToDelete] - : dataDevices?.map((device: { endpoint: string }) => device.endpoint) ?? - []; - - for (const ep of endpointsToDelete) { + if (endpointToDelete) { try { await axios.delete( `/api/v1/user/${user?.id}/pushSubscription/${encodeURIComponent( - ep + endpointToDelete )}` ); } catch { - // Ignore individual deletion failures - backend cleanup is best effort + // Ignore deletion failures - backend cleanup is best effort } } @@ -174,19 +170,17 @@ const UserWebPushSettings = () => { useEffect(() => { const verifyWebPush = async () => { const enabled = await verifyPushSubscription(user?.id, currentSettings); - const hasBackendSubscriptions = dataDevices && dataDevices.length > 0; - const isEnabled = enabled || hasBackendSubscriptions; - setWebPushEnabled(isEnabled); + setWebPushEnabled(enabled); localStorage.setItem( 'pushNotificationsEnabled', - isEnabled ? 'true' : 'false' + enabled ? 'true' : 'false' ); }; if (user?.id) { verifyWebPush(); } - }, [user?.id, currentSettings, dataDevices]); + }, [user?.id, currentSettings]); useEffect(() => { const getSubscriptionEndpoint = async () => {