Use a pinia store to manage session state
Replace the convoluted useAccountSession composable with a pinia store that in addition allows for the consolidation of all session related functions to grouped into one module.
This commit is contained in:
parent
c47452a8b4
commit
fae8b4e2e4
21 changed files with 181 additions and 118 deletions
|
@ -1,10 +1,10 @@
|
|||
<template>
|
||||
<main>
|
||||
<h1>Account Settings</h1>
|
||||
<p v-if="session?.account.type !== 'anonymous'">
|
||||
Name: {{ session?.account.name }}
|
||||
<p v-if="sessionStore.account?.type !== 'anonymous'">
|
||||
Name: {{ sessionStore.account?.name }}
|
||||
</p>
|
||||
<p>Access: {{ session?.account.type }}</p>
|
||||
<p>Access: {{ sessionStore.account?.type }}</p>
|
||||
<form @submit.prevent="changeSettings">
|
||||
<label>
|
||||
Timezone
|
||||
|
@ -34,9 +34,9 @@ definePageMeta({
|
|||
middleware: ["authenticated"],
|
||||
});
|
||||
|
||||
const { data: session, refresh: sessionRefresh } = await useAccountSession();
|
||||
const sessionStore = useSessionStore();
|
||||
|
||||
const timezone = ref(session.value?.account.timezone ?? "");
|
||||
const timezone = ref(sessionStore.account?.timezone ?? "");
|
||||
|
||||
async function changeSettings() {
|
||||
try {
|
||||
|
@ -46,7 +46,7 @@ async function changeSettings() {
|
|||
timezone: timezone.value,
|
||||
}
|
||||
});
|
||||
await sessionRefresh();
|
||||
await sessionStore.fetch();
|
||||
} catch (err: any) {
|
||||
alert(err.data.message);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ async function deleteAccount() {
|
|||
await $fetch.raw("/api/account", {
|
||||
method: "DELETE",
|
||||
});
|
||||
await sessionRefresh();
|
||||
await sessionStore.fetch();
|
||||
await navigateTo("/");
|
||||
|
||||
} catch (err: any) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue