feat(web): auth/ui/notifications pinia stores + theme composable

This commit is contained in:
2026-04-29 07:45:20 +08:00
parent 35b812e594
commit 7c164f6aea
4 changed files with 108 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
export interface User {
id: string
email: string
display_name: string
is_admin: boolean
}
export const useAuthStore = defineStore('auth', () => {
const token = ref<string | null>(localStorage.getItem('token'))
const user = ref<User | null>(
JSON.parse(localStorage.getItem('user') || 'null') as User | null,
)
const isAuthenticated = computed(() => !!token.value)
function setSession(t: string, u: User) {
token.value = t
user.value = u
localStorage.setItem('token', t)
localStorage.setItem('user', JSON.stringify(u))
}
function clearSession() {
token.value = null
user.value = null
localStorage.removeItem('token')
localStorage.removeItem('user')
}
return { token, user, isAuthenticated, setSession, clearSession }
})