fix: logout without pwa (#528)

pull/532/head
Joaquín Sánchez 2022-12-23 19:28:10 +01:00 zatwierdzone przez GitHub
rodzic cd268c9bc7
commit 6037700197
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 9 dodań i 4 usunięć

Wyświetl plik

@ -65,8 +65,11 @@ async function loginTo(user?: Omit<UserLogin, 'account'> & { account?: AccountCr
const [me, instance, pushSubscription] = await Promise.all([
masto.accounts.verifyCredentials(),
masto.instances.fetch(),
// we get 404 response instead empty data
masto.pushSubscriptions.fetch().catch(() => Promise.resolve(undefined)),
// if PWA is not enabled, don't get push subscription
useRuntimeConfig().public.pwaEnabled
// we get 404 response instead empty data
? masto.pushSubscriptions.fetch().catch(() => Promise.resolve(undefined))
: Promise.resolve(undefined),
])
user.account = me
@ -104,8 +107,10 @@ export async function removePushNotificationData(user: UserLogin, fromSWPushMana
// clear push notification policy
delete useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {}).value[acct]
const pwaEnabled = useRuntimeConfig().public.pwaEnabled
// we remove the sw push manager if required and there are no more accounts with subscriptions
if (fromSWPushManager && (users.value.length === 0 || users.value.every(u => !u.pushSubscription))) {
if (pwaEnabled && fromSWPushManager && (users.value.length === 0 || users.value.every(u => !u.pushSubscription))) {
// clear sw push subscription
try {
const registration = await navigator.serviceWorker.ready
@ -120,7 +125,7 @@ export async function removePushNotificationData(user: UserLogin, fromSWPushMana
}
export async function removePushNotifications(user: UserLogin) {
if (!useRuntimeConfig().public.pwaEnabled || !user.pushSubscription)
if (!user.pushSubscription)
return
// unsubscribe push notifications