mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 08:40:28 +00:00
remove auth store
This commit is contained in:
parent
213245f82e
commit
785433ae3c
1 changed files with 0 additions and 47 deletions
|
@ -1,47 +0,0 @@
|
||||||
import { defineStore } from "pinia";
|
|
||||||
import { useLocalStorage } from "@vueuse/core";
|
|
||||||
import { UserClient } from "~~/lib/api/user";
|
|
||||||
import { UserOut } from "~~/lib/api/types/data-contracts";
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore("auth", {
|
|
||||||
state: () => ({
|
|
||||||
token: useLocalStorage("pinia/auth/token", ""),
|
|
||||||
attachmentToken: useLocalStorage("pinia/auth/attachmentToken", ""),
|
|
||||||
expires: useLocalStorage("pinia/auth/expires", ""),
|
|
||||||
self: null as UserOut | null,
|
|
||||||
}),
|
|
||||||
getters: {
|
|
||||||
isTokenExpired: state => {
|
|
||||||
if (!state.expires) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof state.expires === "string") {
|
|
||||||
return new Date(state.expires) < new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
return state.expires < new Date();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
async logout(api: UserClient) {
|
|
||||||
const result = await api.user.logout();
|
|
||||||
|
|
||||||
this.token = "";
|
|
||||||
this.attachmentToken = "";
|
|
||||||
this.expires = "";
|
|
||||||
this.self = null;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* clearSession is used when the user cannot be logged out via the API and
|
|
||||||
* must clear it's local session, usually when a 401 is received.
|
|
||||||
*/
|
|
||||||
clearSession() {
|
|
||||||
this.token = "";
|
|
||||||
this.expires = "";
|
|
||||||
navigateTo("/");
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue