Correção de integração com o resend

This commit is contained in:
Guilherme Bano
2026-02-20 23:38:13 -03:00
committed by Felipe Coutinho
parent 446ab0bb38
commit 94f6b0a986
7 changed files with 34 additions and 7 deletions

16
lib/email/resend.ts Normal file
View File

@@ -0,0 +1,16 @@
import { config } from "dotenv";
/**
* Endereço "from" para envio de e-mails via Resend.
* Lê RESEND_FROM_EMAIL do .env (valor deve estar entre aspas se tiver espaço:
* Garante carregamento do .env no contexto da chamada (ex.: Server Actions).
*/
const FALLBACK_FROM = "OpenMonetis <noreply@resend.dev>";
export function getResendFromEmail(): string {
// Garantir que .env foi carregado (não sobrescreve variáveis já definidas)
config({ path: ".env" });
const raw = process.env.RESEND_FROM_EMAIL;
const value = typeof raw === "string" ? raw.trim() : "";
return value.length > 0 ? value : FALLBACK_FROM;
}

View File

@@ -1,6 +1,7 @@
import { inArray } from "drizzle-orm";
import { Resend } from "resend";
import { pagadores } from "@/db/schema";
import { getResendFromEmail } from "@/lib/email/resend";
import { db } from "@/lib/db";
type ActionType = "created" | "deleted";
@@ -118,8 +119,7 @@ export async function sendPagadorAutoEmails({
}
const resendApiKey = process.env.RESEND_API_KEY;
const resendFrom =
process.env.RESEND_FROM_EMAIL ?? "OpenMonetis <onboarding@resend.dev>";
const resendFrom = getResendFromEmail();
if (!resendApiKey) {
console.warn(