Reviewed-on: https://codeberg.org/lvl0/trip-planner/pulls/23 Co-authored-by: myrmidex <myrmidex@myrmidex.net> Co-committed-by: myrmidex <myrmidex@myrmidex.net>
26 lines
No EOL
553 B
JavaScript
26 lines
No EOL
553 B
JavaScript
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; |