From b2e21db0b3a71ff9d277109db3d6b3221731b39f Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 21:07:39 +0900 Subject: [PATCH] fix logout behavior when there is no push subscription 2 --- src/client/account.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index 97085aca47..efe9f19527 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -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