File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -414,7 +414,7 @@ pub async fn get_or_generate_vapid_keys(pool: &DbPool) -> eyre::Result<VapidKeys
414414
415415 let private_key = private_key_pem;
416416 let public_key_raw = key_pair. public_key_raw ( ) ;
417- let public_key = general_purpose:: URL_SAFE_NO_PAD . encode ( & public_key_raw) ;
417+ let public_key = general_purpose:: URL_SAFE . encode ( public_key_raw) ;
418418
419419 store_kv ( pool, KV_VAPID_PRIVATE_KEY , & private_key) . await ?;
420420 store_kv ( pool, KV_VAPID_PUBLIC_KEY , & public_key) . await ?;
Original file line number Diff line number Diff line change @@ -573,9 +573,20 @@ const setupPushNotifications = async () => {
573573
574574 // Subscribe
575575 const registration = await navigator . serviceWorker . ready ;
576+ const applicationServerKey = urlBase64ToUint8Array ( publicKey ) as BufferSource ;
577+ console . log ( 'VAPID public key:' , publicKey ) ;
578+ console . log ( 'Application server key length:' , applicationServerKey . byteLength ) ;
579+
580+ // Unsubscribe any existing subscription to avoid key mismatch
581+ const existingSubscription = await registration . pushManager . getSubscription ( ) ;
582+ if ( existingSubscription ) {
583+ await existingSubscription . unsubscribe ( ) ;
584+ console . info ( 'Unsubscribed from existing push subscription' ) ;
585+ }
586+
576587 const subscription = await registration . pushManager . subscribe ( {
577588 userVisibleOnly : true ,
578- applicationServerKey : urlBase64ToUint8Array ( publicKey ) as BufferSource
589+ applicationServerKey
579590 } ) ;
580591
581592 // Send subscription to server
You can’t perform that action at this time.
0 commit comments