18 lines
420 B
TypeScript
18 lines
420 B
TypeScript
|
|
import type { ReactNode } from 'react';
|
||
|
|
import { Navigate } from 'react-router-dom';
|
||
|
|
import { useAuthStore } from '../../store/useAuthStore';
|
||
|
|
|
||
|
|
interface ProtectedRouteProps {
|
||
|
|
children: ReactNode;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||
|
|
const { isAuthenticated } = useAuthStore();
|
||
|
|
|
||
|
|
if (!isAuthenticated) {
|
||
|
|
return <Navigate to="/login" replace />;
|
||
|
|
}
|
||
|
|
|
||
|
|
return <>{children}</>;
|
||
|
|
}
|