DuOrigin v2 - React + NestJS + Prisma + EUDR API Integration

This commit is contained in:
2026-02-09 09:10:15 -03:00
parent cb90bad239
commit 4122dc6f3b
170 changed files with 31333 additions and 200 deletions

View File

@@ -0,0 +1,31 @@
import { Navigate, useLocation } from 'react-router-dom';
import { useAuth } from '@/hooks/useAuth';
import { Loader2 } from 'lucide-react';
interface ProtectedRouteProps {
children: React.ReactNode;
adminOnly?: boolean;
}
export default function ProtectedRoute({ children, adminOnly = false }: ProtectedRouteProps) {
const { isAuthenticated, isLoading, user } = useAuth();
const location = useLocation();
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-bg">
<Loader2 className="w-8 h-8 text-primary animate-spin" />
</div>
);
}
if (!isAuthenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
}
if (adminOnly && user?.role !== 'admin') {
return <Navigate to="/dashboard" replace />;
}
return <>{children}</>;
}