26 lines
498 B
TypeScript
26 lines
498 B
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { api, type Me } from '../api'
|
|
|
|
export const useSession = defineStore('session', () => {
|
|
const me = ref<Me | null>(null)
|
|
const ready = ref(false)
|
|
|
|
async function refresh() {
|
|
try {
|
|
me.value = await api.me()
|
|
} catch {
|
|
me.value = null
|
|
} finally {
|
|
ready.value = true
|
|
}
|
|
}
|
|
|
|
async function logout() {
|
|
await api.logout()
|
|
me.value = null
|
|
}
|
|
|
|
return { me, ready, refresh, logout }
|
|
})
|