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 HomeView from '@/components/HomeView'
|
||||||
import LoginView from '@/components/LoginView'
|
import LoginView from '@/components/LoginView'
|
||||||
|
import UserView from '@/components/UserView'
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
|
@ -14,6 +15,9 @@ const routes = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/login', component: LoginView
|
path: '/login', component: LoginView
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/user', component: UserView
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const router = VueRouter.createRouter({
|
const router = VueRouter.createRouter({
|
||||||
|
|
|
@ -2,9 +2,8 @@ import { defineStore } from 'pinia'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
export const useSession = defineStore('session', () => {
|
export const useSession = defineStore('session', () => {
|
||||||
let pubkey = ref(null)
|
const pubkey = ref(null)
|
||||||
// eslint-disable-next-line vue/no-ref-as-operand
|
const isAuthenticated = computed(() => !!pubkey.value)
|
||||||
const isAuthenticated = computed(() => !!pubkey)
|
|
||||||
|
|
||||||
async function init () {
|
async function init () {
|
||||||
try {
|
try {
|
||||||
|
@ -24,9 +23,9 @@ export const useSession = defineStore('session', () => {
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then(async r => {
|
||||||
const body = r.json()
|
const body = await r.json()
|
||||||
pubkey = body.pubkey
|
pubkey.value = body.pubkey
|
||||||
return body
|
return body
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue