Fix: Use logged-in user's email for payment

Corrected the email retrieval logic to use the logged-in user's email instead of a hardcoded one when initiating Mercado Pago payments. This resolves the issue where payments were failing due to incorrect email addresses.
This commit is contained in:
gpt-engineer-app[bot] 2025-06-15 20:21:56 +00:00
parent f91efb3823
commit d7f2847a84

View File

@ -1,4 +1,3 @@
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
import MeuCadastroForm from "@/components/settings/MeuCadastroForm"; import MeuCadastroForm from "@/components/settings/MeuCadastroForm";
import { useState } from "react"; import { useState } from "react";
@ -30,17 +29,16 @@ const Configuracoes = () => {
const handleSubscribe = async () => { const handleSubscribe = async () => {
setIsSubscribing(true); setIsSubscribing(true);
try { try {
const userEmail = localStorage.getItem('userEmail'); const { data: { user } } = await supabase.auth.getUser();
const userId = localStorage.getItem('userId');
if (!userEmail || !userId) { if (!user || !user.id || !user.email) {
toast.error("Sessão inválida. Por favor, faça login novamente."); toast.error("Sessão inválida. Por favor, faça login novamente.");
setIsSubscribing(false); setIsSubscribing(false);
return; return;
} }
const { data, error } = await supabase.functions.invoke('mercado-pago-subscribe', { const { data, error } = await supabase.functions.invoke('mercado-pago-subscribe', {
body: { email: userEmail, userId: userId }, body: { email: user.email, userId: user.id },
}); });
if (error) { if (error) {