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:
Kentai Radiquum 2024-08-11 16:49:39 +05:00
parent a64e4f2036
commit 2c8460c6b0
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 92 additions and 14 deletions

View file

@ -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();
}