mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 06:36:46 +00:00
Bloqueou painel sem assinatura
X-Lovable-Edit-ID: edt-b6b3ebcc-3c2b-45a9-bbf3-9a2f6183f6d7 Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
commit
c4eaec1532
1 changed files with 29 additions and 1 deletions
|
|
@ -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";
|
||||
|
|
@ -80,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 (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||
<div className="h-8 w-8 rounded-full border-2 border-primary border-t-transparent animate-spin" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue