26 lines
553 B
React
26 lines
553 B
React
|
|
import { useAuth } from '../../contexts/AuthContext';
|
||
|
|
|
||
|
|
const ProtectedRoute = ({ children }) => {
|
||
|
|
const { isAuthenticated, isLoading } = useAuth();
|
||
|
|
|
||
|
|
if (isLoading) {
|
||
|
|
return (
|
||
|
|
<div className="loading-container">
|
||
|
|
<div className="loading-spinner">Loading...</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!isAuthenticated) {
|
||
|
|
return (
|
||
|
|
<div className="unauthorized-container">
|
||
|
|
<h2>Access Denied</h2>
|
||
|
|
<p>Please log in to access this page.</p>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return children;
|
||
|
|
};
|
||
|
|
|
||
|
|
export default ProtectedRoute;
|