# Add e-signatures and clickwrap to an app on Vercel

> Add e-signatures and clickwrap to an app on Vercel: keys per environment, a Route Handler on Vercel Functions, VERCEL_ENV, and preview deployment hosts.

Source: https://esigncomply.com/vercel

Platform · Vercel

To add e-signatures and clickwrap to an app on Vercel, store the secret key as an Environment Variable: the test key for Preview and Development, the live key for Production. A Route Handler on Vercel Functions creates the session, and a second one confirms the record against `VERCEL_ENV`. Esign Comply seals the record, and your database keeps the receipt.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/vercel)

`npm install esigncomply @esigncomply/react @esigncomply/browser server-only`

[Vercel quickstart](https://esigncomply.com/docs/quickstart/vercel)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run locally for Vercel before publishing

**VERCEL_ENV**

lib/esigncomply.ts (excerpt)

```ts
export const esc = new EsignComply(process.env.ESIGNCOMPLY_API_KEY!);

// Vercel sets VERCEL_ENV on every deployment: "production", "preview" or "development".
// Production holds the live key and accepts live records only.
export const LIVE = process.env.VERCEL_ENV === "production";
```

**Session function**

`app/api/ceremony/route.ts`

```ts
// app/api/ceremony/route.ts
import { randomUUID } from "node:crypto";
import { savePinned } from "@/lib/ceremony-state";
import { DOCUMENTS, esc, signer } from "@/lib/esigncomply";

// A Route Handler runs as a Vercel Function. The secret key never leaves it.
export async function POST(request: Request) {
  const { data: session, error } = await esc.sessions.create(
    {
      profile: process.env.ESIGNCOMPLY_PROFILE_ID!,
      signer,
      documents: [
        { document: DOCUMENTS.terms!, version: "current" },
        { document: DOCUMENTS.privacy!, version: "current" },
      ],
      // The origin the browser reports: localhost, a preview URL or your production domain.
      context: { url: `${request.headers.get("origin") ?? new URL(request.url).origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return Response.json({ error: error.code, message: error.message }, { status: 502 });

  await savePinned({ signerId: signer.external_id, versionIds: session.documents.map((d) => d.version_id) });
  return Response.json({ clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
}
```

**Signed state**

lib/ceremony-state.ts (excerpt)

```ts
const COOKIE = "esc_ceremony";
const MAX_AGE = 30 * 60; // seconds: the lifetime of a session

function sign(value: string): string {
  const secret = process.env.CEREMONY_STATE_SECRET;
  if (!secret) throw new Error("CEREMONY_STATE_SECRET is not set");
  return createHmac("sha256", secret).update(value).digest("base64url");
}

export async function savePinned(pinned: Pinned): Promise<void> {
  const value = Buffer.from(JSON.stringify({ ...pinned, exp: Date.now() + MAX_AGE * 1000 })).toString("base64url");
  (await cookies()).set(COOKIE, `${value}.${sign(value)}`, {
    httpOnly: true,
    secure: process.env.NODE_ENV === "production",
    sameSite: "lax",
    path: "/",
    maxAge: MAX_AGE,
  });
}

export async function loadPinned(): Promise<Pinned | null> {
  const [value, mac] = ((await cookies()).get(COOKIE)?.value ?? "").split(".");
  if (!value || !mac) return null;
  const expected = Buffer.from(sign(value));
  const given = Buffer.from(mac);
  if (given.length !== expected.length || !timingSafeEqual(given, expected)) return null;
  const state = JSON.parse(Buffer.from(value, "base64url").toString()) as Pinned & { exp: number };
  return state.exp > Date.now() ? { signerId: state.signerId, versionIds: state.versionIds } : null;
}
```

**Confirm function**

`app/api/signup/confirm/route.ts`

```ts
// app/api/signup/confirm/route.ts
import { loadPinned } from "@/lib/ceremony-state";
import { esc, LIVE } from "@/lib/esigncomply";

const SEALED = ["recorded", "timestamped", "anchored"];

export async function POST(request: Request) {
  const { recordId } = await request.json();
  const pinned = await loadPinned();
  const { data: record, error } = await esc.records.get(String(recordId));
  if (error || !pinned) return Response.json({ confirmed: false }, { status: 409 });

  const confirmed =
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === pinned.signerId &&
    JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify([...pinned.versionIds].sort());

  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused");
  if (!confirmed) return Response.json({ confirmed: false }, { status: 409 });
  // Only now create the account, and store record.id and record.receipt with it.
  return Response.json({ confirmed: true, recordId: record.id });
}
```

Integrate with Vercel

## How do you integrate Esign Comply with Vercel?

The integration path on Vercel is Next.js Route Handlers, which run as Vercel Functions. Three things are specific to the platform: the key each environment holds, `VERCEL_ENV` as the test that a deployment is production, and state that does not sit in memory, because two requests can run in two function instances.

Vercel creates a new function invocation for each incoming request, and reuses a function instance when another request arrives soon after the previous one.

Source: [Vercel documentation, Vercel Functions](https://vercel.com/docs/functions), read on November 23, 2026.

[Vercel quickstart](https://esigncomply.com/docs/quickstart/vercel) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Vercel

- **VERCEL_ENV** · `lib/esigncomply.ts`
- **Session function** · `app/api/ceremony/route.ts`
- **Signed state** · `lib/ceremony-state.ts`
- **Confirm function** · `app/api/signup/confirm/route.ts`

Run on 2026-11-26 with Next.js 16.4.6 under next dev, with VERCEL_ENV set by hand to preview and to production, esigncomply 1.0.4, @esigncomply/react 1.0.1, @esigncomply/browser 1.0.4 and the conformance check from esigncomply 1.0.4, against the API in test mode. The Vercel settings are from Vercel's documentation as of 2026-11-23. The code has not yet been run on a Vercel deployment.

Three steps

## How does Esign Comply fit with Vercel?

Each step uses a feature Vercel already has. The secret key stays on the server side of Vercel in all three.

1. **Environment Variables hold the key, one per environment**

   Add `ESIGNCOMPLY_API_KEY` in the project's Environment Variables: the test key applied to Preview and Development, the live key applied to Production only. A preview deployment can then never write a live record. Source: [Vercel documentation, Environment variables](https://vercel.com/docs/environment-variables), read on November 23, 2026.

2. **A Vercel Function creates the session**

   A Next.js Route Handler, `app/api/ceremony/route.ts`, calls `esc.sessions.create` with the secret key and returns the client token. The React hooks run the ceremony in the browser, straight from the signer's device to the API.

3. **A second function confirms against VERCEL_ENV**

   `app/api/signup/confirm/route.ts` reads the record and expects a live one only when `VERCEL_ENV` is `production`. Your database keeps the record ID and the receipt beside the user. Source: [Vercel documentation, System environment variables](https://vercel.com/docs/environment-variables/system-environment-variables), read on November 23, 2026.

Vercel setup

## Where do the key, the preview hosts and the webhook go on Vercel?

Four settings carry an Esign Comply integration on Vercel. What is said here about Vercel was read from its own documentation, and the quickstart has each command.

### Environment variables

Set them in the project's settings under Environment Variables, or with `vercel env add ESIGNCOMPLY_API_KEY --environment production --sensitive`. Changes apply to new deployments only, so redeploy after you add one. `vercel env pull` writes the Development values to `.env.local`.

Source: [Vercel documentation, Environment variables](https://vercel.com/docs/environment-variables), read on November 23, 2026.

### Preview deployments and test mode

A test key refuses a host it does not know. Each Git branch has a stable address, `<project-name>-git-<branch-name>-<scope-slug>.vercel.app`: list that host under Domains in the Esign Comply dashboard as a test origin and open previews through it. List exact hosts, never the shared suffix `vercel.app`.

Source: [Vercel documentation, Generated URLs](https://vercel.com/docs/deployments/generated-urls), read on November 23, 2026.

### The registered domain

Register your custom domain and verify it with one DNS record. A production app on a `vercel.app` host verifies with a file instead: a Route Handler at `app/.well-known/esigncomply.txt/route.ts` serves the token from an Environment Variable.

### The webhook endpoint

Add a Route Handler for the `record.completed` webhook and register its production URL under Webhooks in the Esign Comply dashboard. It backs the confirmation up when the browser closes before your function hears about the record.

Read on November 23, 2026: [Vercel documentation, Environment variables](https://vercel.com/docs/environment-variables), [Vercel documentation, System environment variables](https://vercel.com/docs/environment-variables/system-environment-variables), [Vercel documentation, Generated URLs](https://vercel.com/docs/deployments/generated-urls), [Vercel documentation, Vercel Functions](https://vercel.com/docs/functions), [Vercel documentation, vercel env](https://vercel.com/docs/cli/env).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Vercel app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes on Vercel, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap on Vercel

```
Add Esign Comply clickwrap to my Next.js app on Vercel: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/vercel.md (the steps and the tested code for Vercel)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Vercel facts
- Packages (the only ones that exist): esigncomply (server), @esigncomply/react (hooks) and @esigncomply/browser.
- The secret key is the Environment Variable ESIGNCOMPLY_API_KEY: the test key for Preview and Development, the live key for Production only. Never give it a NEXT_PUBLIC_ name. Never print it.
- Expect live records only when process.env.VERCEL_ENV is "production". A preview deployment also has NODE_ENV "production", so NODE_ENV cannot tell them apart.
- Two requests can run in two function instances. Keep the pinned version IDs in the database, or in an httpOnly cookie signed with a secret. Never in memory.
- A preview deployment runs on its own vercel.app host. Test keys refuse that host until it is listed under Domains as a test origin. List the branch URL, never the shared suffix vercel.app.
- The form is in the server HTML before the page hydrates: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Route Handler app/api/ceremony/route.ts: create the session with esc.sessions.create and an Idempotency-Key, save the signer ID and the pinned version IDs in server-owned state, and return only clientToken, apiUrl and documents.
4. Server Component app/legal/[slug]/page.tsx: render the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Client component: useCeremony({ clientToken, apiUrl }), useDocument for each link, ceremony.observeAssent({ region, checkbox, submit }) from an effect, then ceremony.complete() in the submit handler. Request the session once per page load, from a promise kept outside the component.
6. Route Handler app/api/signup/confirm/route.ts: read the record with esc.records.get and require: status is "recorded", "timestamped" or "anchored"; livemode equals (VERCEL_ENV === "production"); the signer ID and version IDs equal the server-owned state. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures on Vercel?

These are specific to Vercel. Each one was seen while the quickstart's code was run, or is in Vercel's own documentation.

- **A preview deployment is a production build**

  `NODE_ENV` is `production` on a preview, while its key is a test key. Compare `livemode` with `VERCEL_ENV === "production"`. In a local test with `VERCEL_ENV` set to `production` and a test key, the confirm route refused the test record with `409`.

- **Two requests can run in two function instances**

  What your server pinned when it created the session cannot sit in a variable. The quickstart carries it in an httpOnly cookie signed with a secret: in the test, a cookie whose payload had been changed was refused. A table in your database does the same job.

- **A preview host is refused until you list it**

  In a local test, a session requested from `https://myapp-git-main-acme.vercel.app` was refused with `domain_mismatch`, and accepted once that host was a test origin of the domain. Use the branch URL, which stays the same across commits.

## Where are the Vercel quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Vercel quickstart](https://esigncomply.com/docs/quickstart/vercel)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Long guide

  **[Clickwrap in Next.js and Supabase](https://esigncomply.com/guides/nextjs-supabase-clickwrap)**

  The full Next.js build with a database table for the receipt, which is what a Vercel deployment needs.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature on Vercel?

The same record on every stack and platform. Your Vercel code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures on Vercel

### How does test mode work on Vercel preview URLs?

A test key works on a preview once the preview's host is listed as a test origin of your domain. Vercel gives each Git branch a stable address that ends in `vercel.app`: list that host and open previews through it. Without the entry the session is refused with `domain_mismatch`.

### Where should the receipt be stored on Vercel?

In your own database, beside the user, with the record ID. Vercel Functions keep nothing between requests, so the confirm function writes both values to your table once the record is confirmed. Esign Comply keeps the sealed record itself.

### Which key goes in which Vercel environment?

The test key in Preview and Development, the live key in Production only. Vercel applies each Environment Variable to the environments you select, so one name, `ESIGNCOMPLY_API_KEY`, holds a different key in each.

### Do I need a custom domain to go live on Vercel?

No. A production app on a `vercel.app` host registers that host as its domain and verifies it with a file at `/.well-known/esigncomply.txt`, because you cannot add DNS records there. With a custom domain you verify by DNS instead.

### Was this code run on Vercel?

Not yet. It was run on `localhost` with Next.js 16.4.6 and `VERCEL_ENV` set by hand, and the Vercel settings come from Vercel's documentation as of November 23, 2026. Environment scoping, the function runtime and file verification on a `vercel.app` host are proven only by a deployment.

### Other platforms

- [Netlify](https://esigncomply.com/netlify)
- [Cloudflare Workers](https://esigncomply.com/cloudflare-workers)
- [Supabase](https://esigncomply.com/supabase)

### Stacks used with Vercel

- [Next.js](https://esigncomply.com/nextjs)
- [React](https://esigncomply.com/react)
- [Node.js](https://esigncomply.com/nodejs)

[All platforms](https://esigncomply.com/platforms) · [All stacks](https://esigncomply.com/stacks) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Ship the signup on Vercel. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/vercel)

Free plan: 10 live signatures a month and a full test mode. No card required.

Vercel is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Vercel is from Vercel's documentation or from a test run, as marked, on November 23, 2026. `/vercel.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
