DocsGuides
Waitlist forms
The waitlist hero and the newsletter section are plain HTML forms. They post to any URL you give them, so the emails land in your own API route, and they work before JavaScript loads.
1. Point the form at your route
Set action to your route and honeypotName to a field name bots will fill. The section renders that field off screen, hidden from screen readers and skipped by the keyboard.
<HeroWaitlist
id="join"
title="Be first in line"
action="/api/waitlist"
honeypotName="website"
note="One email when we launch. No spam."
/>2. Handle the post
This is a shortened version of the route the demo sites run. It checks the Origin header, drops honeypot hits, validates the address and redirects back with a 303, so a refresh never posts twice.
// app/api/waitlist/route.ts
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export async function POST(request: Request) {
// Refuse posts from other sites (browsers send Origin on form posts).
const origin = request.headers.get("origin");
if (origin && origin !== new URL(request.url).origin) return new Response("Forbidden", { status: 403 });
const form = await request.formData().catch(() => null);
const email = String(form?.get("email") ?? "").trim().toLowerCase();
const back = (joined: string) => Response.redirect(new URL(`/?joined=${joined}#join`, request.url), 303);
// Honeypot: only bots fill the hidden field. Look successful, store nothing.
if (String(form?.get("website") ?? "") !== "") return back("1");
if (email.length > 254 || !EMAIL.test(email)) return back("invalid");
const res = await fetch("https://api.resend.com/contacts", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.RESEND_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ email, segments: [{ id: process.env.RESEND_SEGMENT_ID }] }),
}).catch(() => null);
return back(res?.ok ? "1" : "error");
}The full version, which also handles a contact that already exists and runs in a demo mode without keys, is examples/_lib/waitlist.ts.
3. Store the emails
The example adds each address to a Resend segment. Set RESEND_API_KEY and RESEND_SEGMENT_ID in your environment (on Vercel, under Project Settings, Environment Variables). To use another service, replace the fetch call; the form does not change.
4. Tell the visitor what happened
The route redirects to ?joined=1, invalid or error. Read searchParams in your page and show a message next to the form, in an element with role="status" so screen readers announce it.