16 lines
363 B
TypeScript
16 lines
363 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 } = useAuth();
|
|
|
|
if (!isAuthenticated) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
|