From 4387725bfc3bfb67722976274fda5d35e00e22c6 Mon Sep 17 00:00:00 2001 From: Marcio Bevervanso Date: Mon, 13 Apr 2026 19:04:53 -0300 Subject: [PATCH] feat: auto redirect to stripe checkout on pricing registration --- src/App.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 5e59647..3e1265f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -93,6 +93,31 @@ const AppContent: React.FC = () => { const handleAuthSuccess = async () => { setIsModalOpen(false); await refreshProfile(); + + // Se acabou de fazer o cadastro clicando em um plano pago (monthly), leva direto pro Stripe! + if (authMode === 'register' && selectedPlan === 'monthly') { + try { + const { data: { session } } = await supabase.auth.getSession(); + if (session) { + const res = await fetch(`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/stripe-checkout`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${session.access_token}`, + }, + body: JSON.stringify({ plan: "mensal" }) + }); + const { url, error } = await res.json(); + if (!error && url) { + window.location.href = url; // Redireciona pro Checkout + return; + } + } + } catch (e) { + console.error("Falha ao redirecionar para o checkout:", e); + } + } + // Login intent logic handled inside context or simply by state update localStorage.removeItem('login_intent'); };