Custom Domains
Let users connect their own domains using the Vercel Domains API with DNS verification.
Allow users to connect their own domains to your SaaS in ~10 minutes. Uses the Vercel Domains API for domain registration and DNS verification status polling.
How It Works
- User enters a domain in the settings UI (
domain-settings.tsx) - Your API calls Vercel's Domains API to register the domain on your project
- Vercel returns DNS records the user must configure
- The UI polls for verification status: pending → verified → active
- Once active, the domain routes to your app
Files
| File | Purpose |
|---|---|
components/features/custom-domains/domain-settings.tsx | Complete domain management UI — add, verify, delete |
Setup
1
Get Vercel credentials
- Go to vercel.com/account/tokens → Create Token
- Get your Project ID from Vercel → Your Project → Settings → General
- Optionally note your Team ID (Vercel → Team → Settings → General)
2
Add environment variables
VERCEL_API_TOKEN="your_vercel_api_token"
VERCEL_PROJECT_ID="your_vercel_project_id"
VERCEL_TEAM_ID="your_team_id" # Optional: only if using a team account3
Create the domains API route
Create app/api/domains/route.ts with GET (list), POST (add), and DELETE (remove) handlers — see README.md in components/features/custom-domains/ for the full implementation.
4
Create the verify endpoint
Create app/api/domains/verify/route.ts — called by the UI to check if DNS records have propagated.
5
Add to settings
import { DomainSettings } from "@/components/features/custom-domains/domain-settings"
export default function SettingsPage() {
return <DomainSettings />
}Environment Variables
| Variable | Required | Description |
|---|---|---|
VERCEL_API_TOKEN | Yes | Vercel personal access token |
VERCEL_PROJECT_ID | Yes | Vercel project ID |
VERCEL_TEAM_ID | No | Vercel team ID (only for team accounts) |
DNS Configuration for Users
| Type | Name | Value |
|---|---|---|
| CNAME | subdomain | cname.vercel-dns.com |
| A | @ (root domain) | 76.76.21.21 |
Root domains require an A record. Subdomains use CNAME.
Verification
- Set env vars and start dev server
- Navigate to your settings page → enter a test subdomain (e.g.,
test.yourdomain.com) - Confirm it shows "Pending" status with DNS instructions
- Configure the DNS record and click Verify — status changes to "Verified" once propagated
- Delete the test domain to confirm removal works