mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 11:16:46 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
4a08c31ad2
commit
f02fcdd2a2
1 changed files with 26 additions and 1 deletions
|
|
@ -83,13 +83,38 @@ function PainelLayout() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [mobileOpen, setMobileOpen] = useState(false);
|
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(() => {
|
useEffect(() => {
|
||||||
if (!loading && !user) {
|
if (!loading && !user) {
|
||||||
navigate({ to: "/login", search: { redirect: location.pathname } });
|
navigate({ to: "/login", search: { redirect: location.pathname } });
|
||||||
}
|
}
|
||||||
}, [loading, user, navigate, 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 (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
<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" />
|
<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