From f02fcdd2a227de7e85e311c7378d11db83ac68bc Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 17:53:01 +0000 Subject: [PATCH] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- src/routes/painel.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/routes/painel.tsx b/src/routes/painel.tsx index fd555bf..cd7d44b 100644 --- a/src/routes/painel.tsx +++ b/src/routes/painel.tsx @@ -83,13 +83,38 @@ function PainelLayout() { const location = useLocation(); const [mobileOpen, setMobileOpen] = useState(false); + // Faturamento permanece acessível mesmo sem assinatura ativa + // (para que o usuário possa ver o estado e assinar / gerenciar). + const skipSubGuard = location.pathname.startsWith("/painel/faturamento"); + + const { data: hasActiveSub, isLoading: subLoading } = useQuery({ + queryKey: ["has-active-subscription", user?.id, PADDLE_ENV], + enabled: !!user && !skipSubGuard, + queryFn: async () => { + const { data, error } = await supabase.rpc("has_active_subscription", { + user_uuid: user!.id, + check_env: PADDLE_ENV, + }); + if (error) throw error; + return data === true; + }, + }); + useEffect(() => { if (!loading && !user) { navigate({ to: "/login", search: { redirect: location.pathname } }); } }, [loading, user, navigate, location.pathname]); - if (loading || !user) { + useEffect(() => { + if (!loading && user && !skipSubGuard && !subLoading && hasActiveSub === false) { + window.location.href = "/#planos"; + } + }, [loading, user, skipSubGuard, subLoading, hasActiveSub]); + + const checkingSub = !skipSubGuard && (subLoading || hasActiveSub === false); + + if (loading || !user || checkingSub) { return (