From 4a08c31ad2105649cd7f0b4286150786c5a7d165 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:52:47 +0000 Subject: [PATCH 1/2] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- src/routes/painel.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/routes/painel.tsx b/src/routes/painel.tsx index f2df24b..fd555bf 100644 --- a/src/routes/painel.tsx +++ b/src/routes/painel.tsx @@ -13,9 +13,12 @@ import { Sparkles, User, } from "lucide-react"; +import { useQuery } from "@tanstack/react-query"; import { supabase } from "@/integrations/supabase/client"; import { useAuth } from "@/hooks/use-auth"; import { useProfile } from "@/hooks/use-profile"; + +const PADDLE_ENV = (import.meta.env.VITE_PADDLE_ENVIRONMENT as string) === "production" ? "live" : "sandbox"; import { Logo } from "@/components/mika/Logo"; import { ThemeToggle } from "@/components/mika/ThemeToggle"; import { Button } from "@/components/ui/button"; 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 2/2] 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 (