Skip to content

Commit 0a01b87

Browse files
committed
More experiments trying to get VAPID to work
1 parent a2e4e69 commit 0a01b87

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

coordinator/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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?;

frontend/assets/app.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)