Files
LiquidCode_Frontend/src/components/router/ProtectedRoute.tsx
Виталий Лавшонок 56b6f9b339 group posts
2025-11-15 22:23:26 +03:00

15 lines
446 B
TypeScript

// src/routes/ProtectedRoute.tsx
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useAppSelector } from '../../redux/hooks';
export default function ProtectedRoute() {
const isAuthenticated = useAppSelector((state) => !!state.auth.jwt);
const location = useLocation();
if (!isAuthenticated) {
return <Navigate to="/home/login" replace state={{ from: location }} />;
}
return <Outlet />;
}