generated from muhtadeetaron/nextjs-template
fix(nav): improve navigation for authorization routes
This commit is contained in:
@ -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 });
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user