feat: integrate free email domain validation in contact forms

- Added the `free-email-domains` package to validate email addresses in the contact forms.
- Implemented checks to reject free email providers for sales inquiries in both the API and UI components.
- Updated the `pnpm-lock.yaml` and `package.json` files to include the new dependency.
This commit is contained in:
Mauricio Siu
2026-05-04 14:35:21 -06:00
parent 926f4e30a5
commit 455f877643
4 changed files with 34 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { Resend } from "resend";
const FREE_EMAIL_DOMAINS: Set<string> = new Set(require("free-email-domains"));
interface ContactFormData {
inquiryType: "support" | "sales";
firstName: string;
@@ -52,6 +54,17 @@ export async function POST(request: NextRequest) {
);
}
// Reject free email providers for sales inquiries
if (body.inquiryType === "sales") {
const domain = body.email.split("@")[1]?.toLowerCase();
if (domain && FREE_EMAIL_DOMAINS.has(domain)) {
return NextResponse.json(
{ error: "Please use your work email address to contact sales" },
{ status: 400 },
);
}
}
// Submit to HubSpot if it's a sales inquiry
if (body.inquiryType === "sales") {
try {

View File

@@ -12,6 +12,8 @@ import {
} from "@/components/ui/select";
import { useState } from "react";
const FREE_EMAIL_DOMAINS: Set<string> = new Set(require("free-email-domains"));
interface ContactFormData {
inquiryType: "" | "support" | "sales";
deploymentType: "" | "cloud" | "self-hosted";
@@ -69,6 +71,12 @@ export function ContactForm({
newErrors.email = "Email is required";
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
newErrors.email = "Please enter a valid email address";
} else if (
formData.inquiryType === "sales" &&
FREE_EMAIL_DOMAINS.has(formData.email.split("@")[1]?.toLowerCase())
) {
newErrors.email =
"Please use your work email address to contact sales";
}
if (!formData.company.trim()) {
newErrors.company = "Company name is required";

View File

@@ -35,6 +35,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"framer-motion": "^11.3.19",
"free-email-domains": "^1.2.26",
"hast-util-to-jsx-runtime": "^2.3.5",
"lucide-react": "0.364.0",
"next": "16.1.5",