Fix session store sync
This commit is contained in:
parent
a641733444
commit
57673f7b39
|
@ -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>
|
|
@ -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({
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue