From 0dc8251ec7a4c46bc99af5dc417e8396c8629b47 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 12 Feb 2026 02:12:42 +0100 Subject: [PATCH] a --- frontend/src/main.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index 8fe9419..2a03a04 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -847,6 +847,13 @@ async function setupPush() { const vapidResponse = await fetch(`${API_URL}/notifications/vapid-key`); const { publicKey } = await vapidResponse.json(); + // Always clear existing subscription to ensure we use latest VAPID key + const existingSub = await state.swRegistration.pushManager.getSubscription(); + if (existingSub) { + await existingSub.unsubscribe(); + console.log('Unsubscribed existing push subscription'); + } + const subscription = await state.swRegistration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array(publicKey) @@ -870,7 +877,11 @@ async function setupPush() { } function b64(buffer) { - return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer))); + const binary = String.fromCharCode.apply(null, new Uint8Array(buffer)); + return btoa(binary) + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=/g, ''); } function urlBase64ToUint8Array(base64String) {