chore : move all to root

This commit is contained in:
Thibault Pouch
2026-02-26 16:16:44 +01:00
parent 308a758e79
commit c2d94a349c
44 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { Navigate, useLocation } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext';
interface ProtectedRouteProps {
children: React.ReactNode;
/** If true, requires staff role (dev or com). */
staffOnly?: boolean;
/** Redirect destination when access is denied. Defaults to /login. */
redirectTo?: string;
}
export function ProtectedRoute({
children,
staffOnly = false,
redirectTo = '/login',
}: ProtectedRouteProps) {
const { isAuthenticated, isStaff } = useAuth();
const location = useLocation();
if (!isAuthenticated) {
return <Navigate to={redirectTo} state={{ from: location }} replace />;
}
if (staffOnly && !isStaff) {
return <Navigate to="/" replace />;
}
return <>{children}</>;
}