15 lines
508 B
TypeScript
15 lines
508 B
TypeScript
import React from 'react';
|
|
import { Navigate } from 'react-router-dom';
|
|
import { useAuth } from '../../context/AuthContext';
|
|
|
|
export const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
const { isAuthenticated, isLoading } = useAuth();
|
|
|
|
if (isLoading) return <div className="min-h-screen flex items-center justify-center text-indigo-500">LOADING PROTOCOLS...</div>;
|
|
|
|
if (!isAuthenticated) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}; |