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 { 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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user