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
This commit is contained in:
Andrej Spielmann
2026-03-26 13:53:46 +01:00
parent e42f5e2315
commit f7bd930ad7
+5 -1
View File
@@ -15,6 +15,7 @@ interface AuthState {
logout: () => void
login: (username: string, password: string) => Promise<void>
checkAuth: () => Promise<void>
setHydrated: () => void
}
export const useAuth = create<AuthState>()(
@@ -23,10 +24,12 @@ export const useAuth = create<AuthState>()(
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<AuthState>()(
onRehydrateStorage: () => (state) => {
if (state) {
state.isHydrated = true
state.isLoading = false
}
},
}