Next.js SDK
@subdomainto/nextjs v0.1 supports Next.js 14 through 16 on Node.js 20+. Both exported helpers are server-only.
Installation
npm install @subdomainto/nextjs
Create the client
import { createSubdomainToClient } from '@subdomainto/nextjs';
const client = createSubdomainToClient();
const domain = await client.domains.create('portal.customer.com', 'customer-42-domain');
The helper reads the server variables SUBDOMAINTO_API_KEY and optional SUBDOMAINTO_BASE_URL. Do not import it into a Client Component.
Verify a Route Handler webhook
import { verifyWebhookRequest } from '@subdomainto/nextjs';
export async function POST(request: Request) {
const event = await verifyWebhookRequest(request);
return new Response(null, { status: 204 });
}
verifyWebhookRequest reads the raw request body, the SubdomainTo-Signature header, and SUBDOMAINTO_WEBHOOK_SECRET. It rejects invalid signatures, stale timestamps, and malformed payloads.