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:
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user