Correção de integração com o resend
This commit is contained in:
committed by
Felipe Coutinho
parent
446ab0bb38
commit
94f6b0a986
@@ -25,7 +25,7 @@ DB_PORT=5432
|
||||
# === Email (Opcional) ===
|
||||
# Provider: Resend (https://resend.com)
|
||||
RESEND_API_KEY=
|
||||
RESEND_FROM_EMAIL=OpenMonetis <noreply@seudominio.com>
|
||||
RESEND_FROM_EMAIL="OpenMonetis <noreply@seudominio.com>"
|
||||
|
||||
# === OAuth (Opcional) ===
|
||||
# Google: https://console.cloud.google.com/apis/credentials
|
||||
|
||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -5,6 +5,17 @@ Todas as mudanças notáveis deste projeto serão documentadas neste arquivo.
|
||||
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/),
|
||||
e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/).
|
||||
|
||||
## [1.6.3] - 2026-02-19
|
||||
|
||||
### Corrigido
|
||||
|
||||
- E-mail Resend: variável `RESEND_FROM_EMAIL` não era lida do `.env` (valores com espaço precisam estar entre aspas). Leitura centralizada em `lib/email/resend.ts` com `getResendFromEmail()` e carregamento explícito do `.env` no contexto de Server Actions
|
||||
|
||||
### Alterado
|
||||
|
||||
- `.env.example`: `RESEND_FROM_EMAIL` com valor entre aspas e comentário para uso em Docker/produção
|
||||
- `docker-compose.yml`: env do app passa `RESEND_FROM_EMAIL` (em vez de `EMAIL_FROM`) para o container, alinhado ao nome usado pela aplicação
|
||||
|
||||
## [1.6.2] - 2026-02-19
|
||||
|
||||
### Corrigido
|
||||
|
||||
@@ -5,6 +5,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { Resend } from "resend";
|
||||
import { z } from "zod";
|
||||
import { lancamentos, pagadores } from "@/db/schema";
|
||||
import { getResendFromEmail } from "@/lib/email/resend";
|
||||
import { getUser } from "@/lib/auth/server";
|
||||
import { db } from "@/lib/db";
|
||||
import {
|
||||
@@ -418,8 +419,7 @@ export async function sendPagadorSummaryAction(
|
||||
}
|
||||
|
||||
const resendApiKey = process.env.RESEND_API_KEY;
|
||||
const resendFrom =
|
||||
process.env.RESEND_FROM_EMAIL ?? "OpenMonetis <onboarding@resend.dev>";
|
||||
const resendFrom = getResendFromEmail();
|
||||
|
||||
if (!resendApiKey) {
|
||||
return {
|
||||
|
||||
@@ -93,7 +93,7 @@ services:
|
||||
|
||||
# Configurações de email (se usar)
|
||||
RESEND_API_KEY: ${RESEND_API_KEY:-}
|
||||
EMAIL_FROM: ${EMAIL_FROM:-}
|
||||
RESEND_FROM_EMAIL: ${RESEND_FROM_EMAIL:-}
|
||||
|
||||
# Configurações de OAuth (se usar)
|
||||
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-}
|
||||
|
||||
16
lib/email/resend.ts
Normal file
16
lib/email/resend.ts
Normal 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;
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openmonetis",
|
||||
"version": "1.6.2",
|
||||
"version": "1.6.3",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
|
||||
Reference in New Issue
Block a user