Refactor push subscription logic into a composable
This commit is contained in:
parent
52dfde95d1
commit
b2a5b67096
3 changed files with 128 additions and 97 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue