fix logout behavior when there is no push subscription 2

This commit is contained in:
tamaina 2021-08-31 21:07:39 +09:00
parent f6d8867df2
commit b2e21db0b3
1 changed files with 12 additions and 10 deletions

View File

@ -33,16 +33,18 @@ export async function signout() {
//#region Remove push notification registration
try {
const registration = await navigator.serviceWorker.ready;
const push = await registration.pushManager.getSubscription();
if (push) {
await fetch(`${apiUrl}/sw/unregister`, {
method: 'POST',
body: JSON.stringify({
i: $i.token,
endpoint: push.endpoint,
}),
});
if (navigator.serviceWorker.controller) {
const registration = await navigator.serviceWorker.ready;
const push = await registration.pushManager.getSubscription();
if (push) {
await fetch(`${apiUrl}/sw/unregister`, {
method: 'POST',
body: JSON.stringify({
i: $i.token,
endpoint: push.endpoint,
}),
});
}
}
} catch (e) {}
//#endregion