You've already forked agentic-coding-workflow
feat(web): auth/ui/notifications pinia stores + theme composable
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
Reference in New Issue
Block a user