From 61d6d8abfe38106cdae7fe511ea7473be214a30b Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Thu, 1 Jan 2026 22:43:39 +1000 Subject: [PATCH] fix: lazy init Resend to avoid build-time errors --- apps/web/src/lib/email.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/web/src/lib/email.ts b/apps/web/src/lib/email.ts index bf7f424..215a29f 100644 --- a/apps/web/src/lib/email.ts +++ b/apps/web/src/lib/email.ts @@ -1,9 +1,20 @@ import { Resend } from 'resend'; -const resend = new Resend(process.env.RESEND_API_KEY); +// Lazy initialization to avoid build-time errors when RESEND_API_KEY is not set +let resend: Resend | null = null; + +function getResend(): Resend { + if (!resend) { + if (!process.env.RESEND_API_KEY) { + throw new Error('RESEND_API_KEY environment variable is not set'); + } + resend = new Resend(process.env.RESEND_API_KEY); + } + return resend; +} export async function sendVerificationEmail(to: string, verificationUrl: string) { - const { error } = await resend.emails.send({ + const { error } = await getResend().emails.send({ from: 'TPMJS ', to, subject: 'Verify your email - TPMJS',