diff --git a/src/components/helper/RequireAuth.tsx b/src/components/helper/RequireAuth.tsx index 6d1f050b..65adf48c 100644 --- a/src/components/helper/RequireAuth.tsx +++ b/src/components/helper/RequireAuth.tsx @@ -37,13 +37,16 @@ const RequireAuth = ({ children }: RequireAuthProps) => { // Explicitly handle 401 redirect from the component level useEffect(() => { - if (userErrorResponse?.response?.status === 401) { + if ( + isResponseError(userResponse) && + userErrorResponse?.response?.status === 401 + ) { // Clear cache to prevent stale data from rendering children // mutate('/sso/userinfo', undefined, { revalidate: false }); // Optional: if using global mutate setUser(undefined); redirectToSSO(); } - }, [userErrorResponse, setUser]); + }, [userErrorResponse, setUser, userResponse]); useEffect(() => { setIsLoadingUser(isLoadingUserResponse);