diff --git a/src/routes/userRoute.tsx b/src/routes/userRoute.tsx index 4a405e9d..711f9e31 100644 --- a/src/routes/userRoute.tsx +++ b/src/routes/userRoute.tsx @@ -8,8 +8,7 @@ interface UserRouteProps { } const UserRoute: React.FC = ({ children }) => { - const [loading, setLoading] = useState(true); - const [ok, setOk] = useState(false); + const [ok, setOk] = useState(true); // Default to true to allow rendering while fetching const navigate = useNavigate(); const { notify } = useGlobalInfoStore(); @@ -27,8 +26,6 @@ const UserRoute: React.FC = ({ children }) => { } } catch (err: any) { handleRedirect(err.response?.data?.error || 'An error occurred. Please login again.'); - } finally { - setLoading(false); // Remove loading state regardless of success or failure } }; @@ -36,16 +33,13 @@ const UserRoute: React.FC = ({ children }) => { setOk(false); if (errorMessage) { notify('error', errorMessage); - } else { - notify('error', 'Please login again to continue'); } navigate('/login'); }; - // Block rendering if loading the authentication status - if (loading) return null; - + // If ok is true, render the children (protected route) return <>{ok ? children : null}; }; export default UserRoute; +