Skip to content

Commit 455f877

Browse files
committed
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.
1 parent 926f4e3 commit 455f877

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

apps/website/app/api/contact/route.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { NextRequest } from "next/server";
44
import { NextResponse } from "next/server";
55
import { Resend } from "resend";
66

7+
const FREE_EMAIL_DOMAINS: Set<string> = new Set(require("free-email-domains"));
8+
79
interface ContactFormData {
810
inquiryType: "support" | "sales";
911
firstName: string;
@@ -52,6 +54,17 @@ export async function POST(request: NextRequest) {
5254
);
5355
}
5456

57+
// Reject free email providers for sales inquiries
58+
if (body.inquiryType === "sales") {
59+
const domain = body.email.split("@")[1]?.toLowerCase();
60+
if (domain && FREE_EMAIL_DOMAINS.has(domain)) {
61+
return NextResponse.json(
62+
{ error: "Please use your work email address to contact sales" },
63+
{ status: 400 },
64+
);
65+
}
66+
}
67+
5568
// Submit to HubSpot if it's a sales inquiry
5669
if (body.inquiryType === "sales") {
5770
try {

apps/website/components/ContactForm.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
} from "@/components/ui/select";
1313
import { useState } from "react";
1414

15+
const FREE_EMAIL_DOMAINS: Set<string> = new Set(require("free-email-domains"));
16+
1517
interface ContactFormData {
1618
inquiryType: "" | "support" | "sales";
1719
deploymentType: "" | "cloud" | "self-hosted";
@@ -69,6 +71,12 @@ export function ContactForm({
6971
newErrors.email = "Email is required";
7072
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
7173
newErrors.email = "Please enter a valid email address";
74+
} else if (
75+
formData.inquiryType === "sales" &&
76+
FREE_EMAIL_DOMAINS.has(formData.email.split("@")[1]?.toLowerCase())
77+
) {
78+
newErrors.email =
79+
"Please use your work email address to contact sales";
7280
}
7381
if (!formData.company.trim()) {
7482
newErrors.company = "Company name is required";

apps/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"class-variance-authority": "^0.7.0",
3636
"clsx": "^2.1.0",
3737
"framer-motion": "^11.3.19",
38+
"free-email-domains": "^1.2.26",
3839
"hast-util-to-jsx-runtime": "^2.3.5",
3940
"lucide-react": "0.364.0",
4041
"next": "16.1.5",

pnpm-lock.yaml

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)