fix(nav): improve navigation for authorization routes

This commit is contained in:
shafin-r
2025-09-08 14:15:27 +06:00
parent 99d6c15e38
commit 53a2228dc9
9 changed files with 55 additions and 63 deletions

View File

@ -35,6 +35,7 @@ const setCookie = (
interface AuthState {
token: string | null;
isLoading: boolean;
hydrated: boolean;
user: UserData | null;
setToken: (token: string | null) => void;
@ -46,6 +47,7 @@ interface AuthState {
export const useAuthStore = create<AuthState>((set, get) => ({
token: null,
isLoading: true,
hydrated: false,
user: null,
setToken: (newToken) => {
@ -59,9 +61,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
try {
const res = await fetch(`${API_URL}/me/profile/`, {
headers: {
Authorization: `Bearer ${token}`,
},
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error("Failed to fetch user info");
@ -85,6 +85,6 @@ export const useAuthStore = create<AuthState>((set, get) => ({
set({ token: storedToken });
await get().fetchUser();
}
set({ isLoading: false });
set({ isLoading: false, hydrated: true });
},
}));