diff --git a/src/components/auth/ProtectedRoute.tsx b/src/components/auth/ProtectedRoute.tsx
index 6c97f2c..f4cc6e1 100644
--- a/src/components/auth/ProtectedRoute.tsx
+++ b/src/components/auth/ProtectedRoute.tsx
@@ -11,6 +11,10 @@ export function ProtectedRoute({ children, allowedRoles = [] }: ProtectedRoutePr
const { user, loading, userRole } = useAuth();
const location = useLocation();
+ console.log('ProtectedRoute - User:', user?.user_metadata);
+ console.log('ProtectedRoute - UserRole do contexto:', userRole);
+ console.log('ProtectedRoute - Roles permitidas:', allowedRoles);
+
if (loading) {
return
Carregando...
;
}
@@ -20,27 +24,30 @@ export function ProtectedRoute({ children, allowedRoles = [] }: ProtectedRoutePr
return ;
}
+ // Pegar o role diretamente dos metadados do usuário
+ const currentRole = user.user_metadata?.role;
+ console.log('ProtectedRoute - Role dos metadados:', currentRole);
+
// Se não houver roles requeridas, permite acesso
if (allowedRoles.length === 0) {
return <>{children}>;
}
// Se o usuário não tiver o role necessário
- if (!allowedRoles.includes(userRole || '')) {
- console.log('Role atual:', userRole);
- console.log('Roles permitidas:', allowedRoles);
+ if (!allowedRoles.includes(currentRole)) {
+ console.log('ProtectedRoute - Acesso negado');
// Redireciona para a página apropriada
- if (userRole === 'school') {
- return ;
- } else if (userRole === 'teacher') {
- return ;
- } else if (userRole === 'student') {
- return ;
+ switch (currentRole) {
+ case 'school':
+ return ;
+ case 'teacher':
+ return ;
+ case 'student':
+ return ;
+ default:
+ return ;
}
-
- // Se não tiver role definido, volta para home
- return ;
}
return <>{children}>;