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