import { Navigate } from 'react-router-dom' import { ReactNode } from 'react' import { useAuth, UserRole } from '../context/AuthContext' interface ProtectedRouteProps { children: ReactNode allowedRoles?: UserRole[] } const getFallbackRoute = (role?: UserRole) => { switch (role) { case 'admin': return '/dashboard' case 'owner': return '/seller' case 'employee': return '/colaborador' case 'delivery': return '/entregas' default: return '/login' } } export function ProtectedRoute({ children, allowedRoles }: ProtectedRouteProps) { const { user, loading } = useAuth() if (loading) { return
Carregando sessao...
} if (!user) { return } if (allowedRoles && !allowedRoles.includes(user.role)) { return } return <>{children} }