fix: improve error handling and stability - no logout on transient errors, add ErrorBoundary, global error logging
This commit is contained in:
@@ -4,14 +4,19 @@ import { useCurrentUser } from '@/api/hooks';
|
||||
|
||||
export function useAuth() {
|
||||
const store = useAuthStore();
|
||||
const { data, isLoading, isError } = useCurrentUser();
|
||||
const { data, isLoading, isError, error } = useCurrentUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (isError) {
|
||||
store.setAuthenticated(false);
|
||||
store.setUser(null);
|
||||
const status = (error as any)?.status || 0;
|
||||
// Only logout on 401 Unauthorized — other errors are transient
|
||||
if (status === 401) {
|
||||
store.setAuthenticated(false);
|
||||
store.setUser(null);
|
||||
}
|
||||
// For 403, 500, network errors: keep session, don't logout
|
||||
}
|
||||
}, [isError, store]);
|
||||
}, [isError, error, store]);
|
||||
|
||||
return {
|
||||
user: store.user,
|
||||
|
||||
Reference in New Issue
Block a user