From f7bd930ad7c79b4e43ce7f18742bdd9a50a210dd Mon Sep 17 00:00:00 2001 From: Andrej Spielmann Date: Thu, 26 Mar 2026 13:53:46 +0100 Subject: [PATCH] Fix isHydrated state for Zustand persist - Add onRehydrateStorage callback to set isHydrated - Initialize isLoading to true and set to false after hydration - Remove manual isHydrated check in page.tsx --- frontend/src/lib/auth.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/auth.ts b/frontend/src/lib/auth.ts index 9c8f0ba..ffc6f0e 100644 --- a/frontend/src/lib/auth.ts +++ b/frontend/src/lib/auth.ts @@ -15,6 +15,7 @@ interface AuthState { logout: () => void login: (username: string, password: string) => Promise checkAuth: () => Promise + setHydrated: () => void } export const useAuth = create()( @@ -23,10 +24,12 @@ export const useAuth = create()( token: null, refreshToken: null, user: null, - isLoading: false, + isLoading: true, isHydrated: false, error: null, + setHydrated: () => set({ isHydrated: true }), + setAuth: (token, refreshToken, user) => { set({ token, refreshToken, user, error: null }) }, @@ -101,6 +104,7 @@ export const useAuth = create()( onRehydrateStorage: () => (state) => { if (state) { state.isHydrated = true + state.isLoading = false } }, }