28 lines
746 B
TypeScript
28 lines
746 B
TypeScript
import { defineStore } from "pinia"
|
|
|
|
export const useAuthStore = defineStore("auth", {
|
|
state: () =>
|
|
({
|
|
logStatus: undefined,
|
|
} as { logStatus: boolean | undefined }),
|
|
actions: {
|
|
async login(username: string, password: string) {
|
|
const res = await apiPost("auth/login/", { username, password })
|
|
if (!res.error.value) this.logStatus = true
|
|
return res
|
|
},
|
|
async logout() {
|
|
const res = await apiPost("auth/logout/")
|
|
if (!res.error.value) this.logStatus = false
|
|
return res
|
|
},
|
|
async updateLogStatus() {
|
|
const res = await apiGet("auth/user/")
|
|
this.logStatus = !res.error.value
|
|
return res
|
|
},
|
|
},
|
|
getters: {
|
|
isLogged: (state) => state.logStatus,
|
|
},
|
|
})
|