Files
smt/stores/user.js
T
nepiedg c883ae7b17 init
2026-01-25 11:45:16 +08:00

29 lines
639 B
JavaScript

import { defineStore } from 'pinia'
import { storage, USER_KEY, SESSION_KEY } from '@/utils/storage'
export const useUserStore = defineStore('user', {
state: () => ({
user: storage.get(USER_KEY),
sessionKey: storage.get(SESSION_KEY),
isLoggedIn: !!storage.get(SESSION_KEY)
}),
actions: {
setUser(user, sessionKey) {
this.user = user
this.sessionKey = sessionKey
this.isLoggedIn = true
storage.set(USER_KEY, user)
storage.set(SESSION_KEY, sessionKey)
},
logout() {
this.user = null
this.sessionKey = null
this.isLoggedIn = false
storage.remove(USER_KEY)
storage.remove(SESSION_KEY)
}
}
})