mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 16:58:47 +01:00
Check vapidKey
This commit is contained in:
parent
1c01e1b0f4
commit
04e1d60e54
1 changed files with 21 additions and 17 deletions
|
@ -147,24 +147,28 @@ export async function initSubscription() {
|
||||||
if (subscription && !backendSubscription) {
|
if (subscription && !backendSubscription) {
|
||||||
// check if account's vapidKey is same as subscription's applicationServerKey
|
// check if account's vapidKey is same as subscription's applicationServerKey
|
||||||
const { vapidKey } = getCurrentAccount();
|
const { vapidKey } = getCurrentAccount();
|
||||||
const { applicationServerKey } = subscription.options;
|
if (vapidKey) {
|
||||||
const vapidKeyStr = urlBase64ToUint8Array(vapidKey).toString();
|
const { applicationServerKey } = subscription.options;
|
||||||
const applicationServerKeyStr = new Uint8Array(
|
const vapidKeyStr = urlBase64ToUint8Array(vapidKey).toString();
|
||||||
applicationServerKey,
|
const applicationServerKeyStr = new Uint8Array(
|
||||||
).toString();
|
applicationServerKey,
|
||||||
const sameKey = vapidKeyStr === applicationServerKeyStr;
|
).toString();
|
||||||
if (sameKey) {
|
const sameKey = vapidKeyStr === applicationServerKeyStr;
|
||||||
// Subscription didn't change
|
if (sameKey) {
|
||||||
|
// Subscription didn't change
|
||||||
|
} else {
|
||||||
|
// Subscription changed
|
||||||
|
console.error('🔔 Subscription changed', {
|
||||||
|
vapidKeyStr,
|
||||||
|
applicationServerKeyStr,
|
||||||
|
sameKey,
|
||||||
|
});
|
||||||
|
// Unsubscribe since backend doesn't have a subscription
|
||||||
|
await subscription.unsubscribe();
|
||||||
|
throw new Error('Subscription key and vapid key changed');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Subscription changed
|
console.warn('No vapidKey found');
|
||||||
console.error('🔔 Subscription changed', {
|
|
||||||
vapidKeyStr,
|
|
||||||
applicationServerKeyStr,
|
|
||||||
sameKey,
|
|
||||||
});
|
|
||||||
// Unsubscribe since backend doesn't have a subscription
|
|
||||||
await subscription.unsubscribe();
|
|
||||||
throw new Error('Subscription key and vapid key changed');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue