Tie push subscriptions to current session

If a user logs out from a device the expectation should be that device
no longer having any association with the user's account.  Any existing
push notifications should thefore be removed on server.  For this reason
tie push notifications to a session, and remove them when the session is
deleted.
This commit is contained in:
Hornwitser 2025-03-07 14:11:07 +01:00
parent 150cb82f5c
commit 52dfde95d1
7 changed files with 39 additions and 15 deletions

View file

@ -8,9 +8,9 @@
</nav>
<div class="account">
<template v-if="session?.account">
{{ session?.account.name || "anonymous" }}
(s:{{ session?.id }} a:{{ session?.account.id }})
{{ session?.account.type }}
{{ session.account.name || "anonymous" }}
(s:{{ session.id }} a:{{ session.account.id }}{{ session.push ? " push" : null }})
{{ session.account.type }}
<button type="button" @click="logOut">Log out</button>
</template>
<template v-else>

View file

@ -99,12 +99,14 @@ async function getSubscription(
const unsupported = ref<boolean | undefined>(undefined);
const subscription = ref<PushSubscription | null>(null);
const runtimeConfig = useRuntimeConfig();
const { refresh: refreshSession } = useAccountSession();
function onClick() {
async function onClick() {
if (!subscription.value)
registerAndSubscribe(runtimeConfig.public.vapidPublicKey, (subs) => { subscription.value = subs })
await registerAndSubscribe(runtimeConfig.public.vapidPublicKey, (subs) => { subscription.value = subs })
else
unsubscribe(subscription.value, () => { subscription.value = null })
await unsubscribe(subscription.value, () => { subscription.value = null })
refreshSession();
}
onMounted(() => {