Fix session store sync

This commit is contained in:
ekzyis 2023-11-07 09:48:01 +01:00
parent a641733444
commit 57673f7b39
3 changed files with 17 additions and 6 deletions

View File

@ -0,0 +1,8 @@
<template>
<div v-if="session.pubkey">authenticated as {{ session.pubkey.slice(0,8) }}</div>
</template>
<script setup>
import { useSession } from '@/stores/session'
const session = useSession()
</script>

View File

@ -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({

View File

@ -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
})
}