Skip to content

Commit db6721f

Browse files
author
Miriad
committed
fix: lazy Resend client initialization to avoid build-time crash
1 parent 2411cd3 commit db6721f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/sponsor/email-service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { Resend } from 'resend'
22

3-
const resend = new Resend(process.env.RESEND_API_KEY)
4-
53
const FROM_EMAIL = 'Alex Patterson <alex@codingcat.dev>'
64

5+
/** Lazy Resend client — only created when actually needed (avoids build-time crash) */
6+
let _resend: Resend | null = null
7+
function getResendClient(): Resend {
8+
if (!_resend) {
9+
_resend = new Resend(process.env.RESEND_API_KEY)
10+
}
11+
return _resend
12+
}
13+
714
/**
815
* Send a sponsor-related email via Resend.
916
* Falls back to console logging if RESEND_API_KEY is not set.
@@ -20,6 +27,7 @@ export async function sendSponsorEmail(
2027
}
2128

2229
try {
30+
const resend = getResendClient()
2331
const { data, error } = await resend.emails.send({
2432
from: FROM_EMAIL,
2533
to: [to],

0 commit comments

Comments
 (0)