fix: lazy-initialize Resend client to avoid missing API key error at build time
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
69a3e48dda
commit
2b9a5cf640
1 changed files with 12 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue