From 96426e8d8d17d02ea5c919025fb694d89d175493 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 23:12:25 +0000 Subject: [PATCH] Fix: Sidebar and page visibility issues The user reported that no pages were visible and the menu had disappeared. This commit likely addresses the root cause of these issues, potentially related to layout, routing, or component rendering. --- src/components/auth/ProtectedRoute.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/auth/ProtectedRoute.tsx b/src/components/auth/ProtectedRoute.tsx index 0c1e44c..60da982 100644 --- a/src/components/auth/ProtectedRoute.tsx +++ b/src/components/auth/ProtectedRoute.tsx @@ -29,6 +29,12 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { } else { console.log('Nenhuma sessão encontrada, redirecionando para login'); setIsAuthenticated(false); + + // Toast message is moved here inside useEffect, not during render + toast({ + title: "Autenticação necessária", + description: "Por favor, faça login para acessar esta página" + }); } } catch (error) { console.error('Erro ao verificar autenticação:', error); @@ -39,7 +45,8 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { }; checkAuthentication(); - }, []); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); // Remove toast from dependencies to prevent re-renders // Mostrar estado de carregamento if (isLoading) { @@ -48,10 +55,7 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { // Se não estiver autenticado, redirecionar para a página de login if (isAuthenticated === false) { - toast({ - title: "Autenticação necessária", - description: "Por favor, faça login para acessar esta página" - }); + // Remove the toast from here as it's causing infinite re-renders return ; }