fix: revert

This commit is contained in:
karishmas6
2024-09-25 16:10:28 +05:30
parent ecd78e2f0f
commit be9697b077

View File

@@ -8,8 +8,7 @@ interface UserRouteProps {
} }
const UserRoute: React.FC<UserRouteProps> = ({ children }) => { const UserRoute: React.FC<UserRouteProps> = ({ children }) => {
const [loading, setLoading] = useState(true); const [ok, setOk] = useState<boolean>(true); // Default to true to allow rendering while fetching
const [ok, setOk] = useState<boolean>(false);
const navigate = useNavigate(); const navigate = useNavigate();
const { notify } = useGlobalInfoStore(); const { notify } = useGlobalInfoStore();
@@ -27,8 +26,6 @@ const UserRoute: React.FC<UserRouteProps> = ({ children }) => {
} }
} catch (err: any) { } catch (err: any) {
handleRedirect(err.response?.data?.error || 'An error occurred. Please login again.'); 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<UserRouteProps> = ({ children }) => {
setOk(false); setOk(false);
if (errorMessage) { if (errorMessage) {
notify('error', errorMessage); notify('error', errorMessage);
} else {
notify('error', 'Please login again to continue');
} }
navigate('/login'); navigate('/login');
}; };
// Block rendering if loading the authentication status // If ok is true, render the children (protected route)
if (loading) return null;
return <>{ok ? children : null}</>; return <>{ok ? children : null}</>;
}; };
export default UserRoute; export default UserRoute;