Refactor push subscription logic into a composable

This commit is contained in:
Hornwitser 2025-03-07 16:08:45 +01:00
parent 52dfde95d1
commit b2a5b67096
3 changed files with 128 additions and 97 deletions

View file

@ -12,6 +12,7 @@
<script lang="ts" setup>
const { data: session, refresh: sessionRefresh } = useAccountSession();
const { getSubscription, subscribe } = usePushNotification();
const name = ref("");
const result = ref("")
@ -22,6 +23,11 @@ async function logIn() {
body: { name: name.value },
});
result.value = `Server replied: ${res.status} ${res.statusText}`;
// Resubscribe push notifications if the user was subscribed before.
const subscription = await getSubscription();
if (subscription) {
await subscribe();
}
await sessionRefresh();
} catch (err: any) {