fix: logout without pwa (#528)

This commit is contained in:
Joaquín Sánchez 2022-12-23 19:28:10 +01:00 committed by GitHub
parent cd268c9bc7
commit 6037700197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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