feat: migrar emails de Resend a Nodemailer + Gmail SMTP
Reemplaza Resend por nodemailer con Gmail SMTP. El to: ahora usa el email real del cliente en lugar del hardcodeado de sandbox. Variables de entorno: GMAIL_USER y GMAIL_APP_PASSWORD. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+14
-7
@@ -1,21 +1,28 @@
|
||||
import { prisma } from "./prisma";
|
||||
import { Resend } from "resend";
|
||||
import nodemailer from "nodemailer";
|
||||
import crypto from "crypto";
|
||||
|
||||
const resend = new Resend(process.env.RESEND_API_KEY);
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: "smtp.gmail.com",
|
||||
port: 587,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env.GMAIL_USER,
|
||||
pass: process.env.GMAIL_APP_PASSWORD,
|
||||
},
|
||||
});
|
||||
|
||||
export async function enviarMagicLink(email: string): Promise<{ ok: boolean; error?: string }> {
|
||||
const cliente = await prisma.cliente.findUnique({ where: { email } });
|
||||
if (!cliente) return { ok: false, error: "Email no registrado" };
|
||||
|
||||
// Invalidar tokens anteriores no usados
|
||||
await prisma.magicToken.updateMany({
|
||||
where: { clienteId: cliente.id, usado: false },
|
||||
data: { usado: true },
|
||||
});
|
||||
|
||||
const token = crypto.randomBytes(32).toString("hex");
|
||||
const expiresAt = new Date(Date.now() + 15 * 60 * 1000); // 15 minutos
|
||||
const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
|
||||
|
||||
await prisma.magicToken.create({
|
||||
data: { clienteId: cliente.id, token, expiresAt },
|
||||
@@ -23,9 +30,9 @@ export async function enviarMagicLink(email: string): Promise<{ ok: boolean; err
|
||||
|
||||
const link = `${process.env.MAGIC_LINK_BASE_URL}/cliente/auth?token=${token}`;
|
||||
|
||||
await resend.emails.send({
|
||||
from: "Taller <onboarding@resend.dev>",
|
||||
to: "jpbeldomenico@gmail.com",
|
||||
await transporter.sendMail({
|
||||
from: `"Taller" <${process.env.GMAIL_USER}>`,
|
||||
to: email,
|
||||
subject: "Tu link de acceso al taller",
|
||||
html: `
|
||||
<h2>Hola ${cliente.nombre}!</h2>
|
||||
|
||||
Reference in New Issue
Block a user