parent
0e41f57ce5
commit
0dc8251ec7
1 changed files with 12 additions and 1 deletions
|
|
@ -847,6 +847,13 @@ async function setupPush() {
|
||||||
const vapidResponse = await fetch(`${API_URL}/notifications/vapid-key`);
|
const vapidResponse = await fetch(`${API_URL}/notifications/vapid-key`);
|
||||||
const { publicKey } = await vapidResponse.json();
|
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({
|
const subscription = await state.swRegistration.pushManager.subscribe({
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: urlBase64ToUint8Array(publicKey)
|
applicationServerKey: urlBase64ToUint8Array(publicKey)
|
||||||
|
|
@ -870,7 +877,11 @@ async function setupPush() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function b64(buffer) {
|
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) {
|
function urlBase64ToUint8Array(base64String) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue