Fix Resend API key error during build

- Move Resend client instantiation from module level to function
- Add validation to skip placeholder API keys
- Set empty RESEND_API_KEY and GOOGLE_SERVICE_ACCOUNT_JSON during build
This commit is contained in:
Marco Gallegos
2026-01-18 15:08:17 -06:00
parent 0351d8ac9d
commit 8bc9c959b5
4 changed files with 51 additions and 157 deletions

View File

@@ -5,7 +5,13 @@ import { format } from 'date-fns'
import { es } from 'date-fns/locale'
import { Resend } from 'resend'
const resend = new Resend(process.env.RESEND_API_KEY!)
function getResendClient() {
const apiKey = process.env.RESEND_API_KEY
if (!apiKey || apiKey === 'placeholder' || apiKey === '<REDACTED>') {
return null
}
return new Resend(apiKey)
}
/** @description Send receipt email for booking */
export async function POST(
@@ -105,6 +111,12 @@ export async function POST(
</html>
`
const resend = getResendClient()
if (!resend) {
console.error('RESEND_API_KEY not configured')
return NextResponse.json({ error: 'Email service not configured' }, { status: 500 })
}
const { data: emailResult, error: emailError } = await resend.emails.send({
from: 'ANCHOR:23 <noreply@anchor23.mx>',
to: booking.customer.email,