2024-01-15 14:42:53 -05:00

29 lines
648 B
JavaScript

import {defineStore} from "pinia";
import {ref} from "vue";
const key = "AUTH"
export const useAuthStore = defineStore('auth', () => {
/** @type {(undefined | any)} */
const auth = ref(JSON.parse(localStorage.getItem(key)) || undefined)
/** @param {(undefined | string)} auth */
function set(auth) {
this.auth = auth
if (auth)
localStorage.setItem(key, JSON.stringify(auth))
else
localStorage.removeItem(key)
}
function isAuth() {
return !!this.auth?.token
}
function getAuth() {
return this.auth
}
return {auth, getAuth, set, isAuth}
})