fix: lazy-initialize Resend client to avoid missing API key error at build time
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-10 22:01:19 +01:00
parent 69a3e48dda
commit 2b9a5cf640

View file

@ -3,7 +3,12 @@ import { render } from '@react-email/components'
import { LeadAlertEmail } from '@/emails/LeadAlert'
import { logger } from '@/lib/logger'
const resend = new Resend(process.env['RESEND_API_KEY'])
function getResend() {
const key = process.env['RESEND_API_KEY']
if (!key) return null
return new Resend(key)
}
const FROM = process.env['RESEND_FROM'] ?? 'noreply@shumiland.ua'
const MANAGER_EMAILS = (process.env['MANAGER_EMAILS'] ?? '').split(',').filter(Boolean)
@ -28,6 +33,12 @@ export async function sendLeadAlert(lead: LeadAlertData): Promise<void> {
})
)
const resend = getResend()
if (!resend) {
logger.warn('RESEND_API_KEY not configured — skipping email alert')
return
}
try {
await resend.emails.send({
from: FROM,