From 57673f7b392f41df98644f20a94b8cf3555eac56 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 7 Nov 2023 09:48:01 +0100 Subject: [PATCH] Fix session store sync --- vue/src/components/UserView.vue | 8 ++++++++ vue/src/main.js | 4 ++++ vue/src/stores/session.js | 11 +++++------ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 vue/src/components/UserView.vue diff --git a/vue/src/components/UserView.vue b/vue/src/components/UserView.vue new file mode 100644 index 0000000..fffa6af --- /dev/null +++ b/vue/src/components/UserView.vue @@ -0,0 +1,8 @@ + + + diff --git a/vue/src/main.js b/vue/src/main.js index cbd7262..19c77a1 100644 --- a/vue/src/main.js +++ b/vue/src/main.js @@ -7,6 +7,7 @@ import './index.css' import HomeView from '@/components/HomeView' import LoginView from '@/components/LoginView' +import UserView from '@/components/UserView' const routes = [ { @@ -14,6 +15,9 @@ const routes = [ }, { path: '/login', component: LoginView + }, + { + path: '/user', component: UserView } ] const router = VueRouter.createRouter({ diff --git a/vue/src/stores/session.js b/vue/src/stores/session.js index 286fc9d..466feae 100644 --- a/vue/src/stores/session.js +++ b/vue/src/stores/session.js @@ -2,9 +2,8 @@ import { defineStore } from 'pinia' import { computed, ref } from 'vue' export const useSession = defineStore('session', () => { - let pubkey = ref(null) - // eslint-disable-next-line vue/no-ref-as-operand - const isAuthenticated = computed(() => !!pubkey) + const pubkey = ref(null) + const isAuthenticated = computed(() => !!pubkey.value) async function init () { try { @@ -24,9 +23,9 @@ export const useSession = defineStore('session', () => { return fetch(url, { credentials: 'include' }) - .then(r => { - const body = r.json() - pubkey = body.pubkey + .then(async r => { + const body = await r.json() + pubkey.value = body.pubkey return body }) }