1
0
Files
coconut-leaf/frontend/src/stores/token.ts
2026-05-15 09:39:15 +08:00

32 lines
546 B
TypeScript

import { defineStore } from 'pinia'
interface TokenState {
token: string | null
}
export const useTokenStore = defineStore('token', {
state: (): TokenState => ({
token: null,
}),
getters: {
isLoggedIn: (state) => typeof state.token === 'string',
currentToken: (state) => state.token as string,
},
actions: {
login(token: string) {
this.token = token;
},
logout() {
this.token = null;
},
},
persist: {
key: 'ccn-token',
storage: localStorage,
pick: ['token'],
},
})