From 7886e531141d1d01ba1bef1b51d42aa527812d3c Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Mon, 6 Oct 2025 22:45:20 -0600 Subject: [PATCH] fix: add API key validation for Resend initialization in contact form --- apps/website/app/api/contact/route.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/website/app/api/contact/route.ts b/apps/website/app/api/contact/route.ts index c9065d5..08ce38c 100644 --- a/apps/website/app/api/contact/route.ts +++ b/apps/website/app/api/contact/route.ts @@ -2,8 +2,6 @@ import type { NextRequest } from "next/server"; import { NextResponse } from "next/server"; import { Resend } from "resend"; -const resend = new Resend(process.env.RESEND_API_KEY || ""); - interface ContactFormData { inquiryType: "support" | "sales" | "other"; name: string; @@ -14,6 +12,17 @@ interface ContactFormData { export async function POST(request: NextRequest) { try { + // Initialize Resend with API key check + const apiKey = process.env.RESEND_API_KEY; + if (!apiKey) { + console.error("RESEND_API_KEY is not configured"); + return NextResponse.json( + { error: "Email service not configured" }, + { status: 500 }, + ); + } + + const resend = new Resend(apiKey); const body: ContactFormData = await request.json(); // Validate required fields