fix: add API key validation for Resend initialization in contact form

This commit is contained in:
Mauricio Siu
2025-10-06 22:45:20 -06:00
parent fada052c69
commit 7886e53114

View File

@@ -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