feat: add persist feature for frontend
This commit is contained in:
30
frontend/src/stores/token.ts
Normal file
30
frontend/src/stores/token.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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',
|
||||
},
|
||||
|
||||
actions: {
|
||||
login(token: string) {
|
||||
this.token = token;
|
||||
},
|
||||
logout() {
|
||||
this.token = null;
|
||||
},
|
||||
},
|
||||
|
||||
persist: {
|
||||
key: 'ccn-token',
|
||||
storage: localStorage,
|
||||
pick: ['token'],
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user