mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-30 18:09:40 +05:00
feat: add disclaimer on first launch
fix: check store hydration before loading pages fix: check user store before loading pages
This commit is contained in:
parent
a64e4f2036
commit
2c8460c6b0
4 changed files with 92 additions and 14 deletions
|
@ -3,26 +3,40 @@ import { create } from "zustand";
|
|||
import { getJWT, removeJWT, fetchDataViaGet } from "#/api/utils";
|
||||
|
||||
interface userState {
|
||||
isAuth: boolean
|
||||
user: Object | null
|
||||
token: string | null
|
||||
state: string,
|
||||
login: (user: Object, token: string) => void
|
||||
logout: () => void
|
||||
checkAuth: () => void
|
||||
_hasHydrated: boolean;
|
||||
isAuth: boolean;
|
||||
user: Object | null;
|
||||
token: string | null;
|
||||
state: string;
|
||||
login: (user: Object, token: string) => void;
|
||||
logout: () => void;
|
||||
checkAuth: () => void;
|
||||
}
|
||||
|
||||
export const useUserStore = create<userState>((set, get) => ({
|
||||
_hasHydrated: false,
|
||||
isAuth: false,
|
||||
user: null,
|
||||
token: null,
|
||||
state: "loading",
|
||||
|
||||
login: (user: Object, token: string) => {
|
||||
set({ isAuth: true, user: user, token: token, state: "finished" });
|
||||
set({
|
||||
isAuth: true,
|
||||
user: user,
|
||||
token: token,
|
||||
state: "finished",
|
||||
_hasHydrated: true,
|
||||
});
|
||||
},
|
||||
logout: () => {
|
||||
set({ isAuth: false, user: null, token: null, state: "finished" });
|
||||
set({
|
||||
isAuth: false,
|
||||
user: null,
|
||||
token: null,
|
||||
state: "finished",
|
||||
_hasHydrated: true,
|
||||
});
|
||||
removeJWT();
|
||||
},
|
||||
checkAuth: () => {
|
||||
|
@ -37,8 +51,8 @@ export const useUserStore = create<userState>((set, get) => ({
|
|||
} else {
|
||||
get().logout();
|
||||
}
|
||||
}
|
||||
_checkAuth()
|
||||
};
|
||||
_checkAuth();
|
||||
} else {
|
||||
get().logout();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue