Something went wrong. Try again.
add or update alt text on your media forked from psingletary.com/verifier
Something went wrong. Try again.
756 B · 22 lines
JSX
at deploy
1234567891011121314151617181920212223import React, { useEffect } from 'react';import { useLocation } from 'react-router-dom';import { useAuth } from '../contexts/AuthContext';
const ProtectedRoute = ({ children }) => { const { isAuthenticated, loading } = useAuth(); const location = useLocation();
useEffect(() => { if (loading) return; if (!isAuthenticated) { const redirectUrl = `/login?returnUrl=${encodeURIComponent(location.pathname + location.search)}`; window.location.replace(redirectUrl); } }, [isAuthenticated, loading, location.pathname, location.search]);
if (loading) return <p>Checking authentication...</p>; if (!isAuthenticated) return <p>Not authenticated — redirecting...</p>; return children;};
export default ProtectedRoute;