feat: auto redirect to stripe checkout on pricing registration
This commit is contained in:
parent
22c36f387b
commit
4387725bfc
1 changed files with 25 additions and 0 deletions
25
src/App.tsx
25
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');
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue