fix logout behavior when there is no push subscription

This commit is contained in:
tamaina 2021-08-31 20:56:01 +09:00
parent 2f3a942583
commit f6d8867df2

View file

@ -35,14 +35,15 @@ export async function signout() {
try {
const registration = await navigator.serviceWorker.ready;
const push = await registration.pushManager.getSubscription();
if (!push) return;
await fetch(`${apiUrl}/sw/unregister`, {
method: 'POST',
body: JSON.stringify({
i: $i.token,
endpoint: push.endpoint,
}),
});
if (push) {
await fetch(`${apiUrl}/sw/unregister`, {
method: 'POST',
body: JSON.stringify({
i: $i.token,
endpoint: push.endpoint,
}),
});
}
} catch (e) {}
//#endregion