import React from 'react'; import { Navigate } from 'react-router-dom'; import { useAuth } from '../../hooks/useAuth'; interface ProtectedRouteProps { children: React.ReactNode; allowedRoles?: string[]; } export function ProtectedRoute({ children, allowedRoles = [] }: ProtectedRouteProps) { const { user, loading, userRole } = useAuth(); if (loading) { return
Carregando...
; } if (!user) { return ; } if (allowedRoles.length > 0 && !allowedRoles.includes(userRole || '')) { // Redirecionar para a página inicial apropriada baseado no papel do usuário switch (userRole) { case 'student': return ; case 'teacher': return ; case 'school': return ; default: return ; } } return <>{children}; }