From 39e6115467bbd238ccbf8b4cdf9e383c8e3db295 Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Mon, 8 Dec 2025 23:51:41 +0100 Subject: [PATCH] fix(webpush): ensure the old endpoint is cleared only when necessary Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- src/utils/pushSubscriptionHelpers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/pushSubscriptionHelpers.ts b/src/utils/pushSubscriptionHelpers.ts index e8b66e049..7cf0906da 100644 --- a/src/utils/pushSubscriptionHelpers.ts +++ b/src/utils/pushSubscriptionHelpers.ts @@ -73,18 +73,21 @@ export const verifyAndResubscribePushSubscription = async ( return false; } + const { subscription } = await getPushSubscription(); const isValid = await verifyPushSubscription(userId, currentSettings); if (isValid) { return true; } + if (subscription) { + return false; + } + if (currentSettings.enablePushRegistration) { try { - // Unsubscribe from the backend to clear the existing push subscription (keys and endpoint) const oldEndpoint = await unsubscribeToPushNotifications(userId); - // Subscribe again to generate a fresh push subscription with updated keys and endpoint await subscribeToPushNotifications(userId, currentSettings); if (oldEndpoint) { @@ -96,7 +99,6 @@ export const verifyAndResubscribePushSubscription = async ( ); } catch (error) { // Ignore errors when deleting old endpoint (it might not exist) - // This is expected when the endpoint was already cleaned up } }