22 lines
526 B
JavaScript
22 lines
526 B
JavaScript
import { defineStore } from 'pinia'
|
|
|
|
export const useAuthStore = defineStore('auth', {
|
|
state: () => ({
|
|
tokens: {},
|
|
}),
|
|
actions: {
|
|
setToken(publicKey, token) {
|
|
this.tokens[publicKey] = token
|
|
localStorage.setItem(publicKey, token)
|
|
},
|
|
clearToken(publicKey) {
|
|
this.tokens[publicKey] = null
|
|
localStorage.removeItem(publicKey)
|
|
},
|
|
loadTokenFromStorage(publicKey) {
|
|
const token = localStorage.getItem(publicKey)
|
|
if (token) this.tokens[publicKey] = token
|
|
}
|
|
},
|
|
})
|