# Add e-signatures and clickwrap to Next.js

> Add e-signatures and clickwrap to Next.js with esigncomply and @esigncomply/react: a Server Component, a client form and a Route Handler. Tested code.

Source: https://esigncomply.com/nextjs

Stack · Next.js

To add e-signatures and clickwrap to Next.js, install `esigncomply` for the server and `@esigncomply/react` for the browser. With Esign Comply you create the session in a Server Component with the secret key, run your own form with the hooks, and confirm the record in a Route Handler. You end with a sealed record that anyone can verify.

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/nextjs)

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

[Next.js quickstart](https://esigncomply.com/docs/quickstart/nextjs)

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

Last updated November 26, 2026

Run in Next.js before publishing

**Server Component**

app/signup/page.tsx (excerpt)

```tsx
export default async function SignupPage() {
  const h = await headers(); // reading the request also makes this page render per request
  const origin = `${h.get("x-forwarded-proto") ?? "http"}://${h.get("host")}`;

  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" },
      ],
      context: { url: `${origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return <p role="alert">We could not start the signup. Reload the page to try again.</p>;

  const versionIds = session.documents.map((d) => d.version_id);
  pinned.set(signer.external_id, versionIds);

  // Only the client token, the API URL and the version IDs cross to the browser.
  return <SignupForm clientToken={session.client_token} apiUrl={session.api_url} versionIds={versionIds} />;
}
```

**Client form**

app/signup/signup-form.tsx (excerpt)

```tsx
export function SignupForm({ clientToken, apiUrl, versionIds }: { clientToken: string; apiUrl: string; versionIds: string[] }) {
  const { ceremony, canComplete, error } = useCeremony({ clientToken, apiUrl });
  const [termsId, privacyId] = versionIds;
  const terms = useDocument<HTMLAnchorElement>(ceremony, { versionId: termsId, mode: "hyperlink" });
  const privacy = useDocument<HTMLAnchorElement>(ceremony, { versionId: privacyId, mode: "hyperlink" });

  const assentRef = useRef<HTMLDivElement>(null);
  const checkboxRef = useRef<HTMLInputElement>(null);
  const submitRef = useRef<HTMLButtonElement>(null);
  const [ready, setReady] = useState(false); // true once the SDK observes the checkbox
  const [message, setMessage] = useState("");

  // Observe the assent controls once both documents are presented.
  useEffect(() => {
    if (!ceremony || !terms.presented || !privacy.presented) return;
    void ceremony
      .observeAssent({
        region: assentRef.current, // notice, links, checkbox, button
        checkbox: checkboxRef.current,
        submit: submitRef.current,
      })
      .then(() => setReady(true));
  }, [ceremony, terms.presented, privacy.presented]);
```

**Route Handler**

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

```ts
// app/api/signup/confirm/route.ts
import { esc, pinned, signer } from "@/lib/esigncomply";

const SEALED = ["recorded", "timestamped", "anchored"];
// Test records in development, live records where ESIGNCOMPLY_LIVE is "true": production only.
const LIVE = process.env.ESIGNCOMPLY_LIVE === "true";

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

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

  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 Next.js

## How do you integrate Esign Comply with Next.js?

In the App Router the session needs no API route of its own. The signup page is a Server Component, so it creates the session while it renders and hands the client token to the form as a prop. The form is a `"use client"` file that calls the hooks, and a Route Handler confirms the record before the account exists.

The App Router is a file-system based router that uses React's latest features such as Server Components, Suspense, and Server Functions.

Source: [Next.js documentation](https://nextjs.org/docs/app), read on November 23, 2026.

[Next.js quickstart](https://esigncomply.com/docs/quickstart/nextjs) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Next.js

- **Server Component** · `app/signup/page.tsx`
- **Client form** · `app/signup/signup-form.tsx`
- **Route Handler** · `app/api/signup/confirm/route.ts`

Run on 2026-11-26 with Next.js 16.4.6 (App Router, Turbopack), React 19.3.1, esigncomply 1.0.4, @esigncomply/react 1.0.1, @esigncomply/browser 1.0.4 and the conformance check from esigncomply 1.0.4 (--timeout 60), against the API in test mode.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Next.js 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 in Next.js, 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 in Next.js

```
Add Esign Comply clickwrap to my Next.js app: 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/nextjs.md (the steps and the tested code for Next.js)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Next.js facts
- Packages (the only ones that exist): esigncomply (server), @esigncomply/react (hooks) and @esigncomply/browser. Use the App Router.
- The secret key is in ESIGNCOMPLY_API_KEY in .env.local. Never give it a NEXT_PUBLIC_ name. Create the client in lib/esigncomply.ts with import "server-only", and never import that file from a "use client" file.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- Module state is not shared between a page and a Route Handler in development. Keep the pinned version IDs in your database. Only for a first local run, a Map on globalThis works.
- A Server Component cannot set cookies. If the pinned state goes into a cookie, create the session in a Route Handler or a Server Action.
- 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. Server Component app/signup/page.tsx: 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 pass only clientToken, apiUrl and the version IDs to the client component.
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. The checkbox is uncontrolled and starts unchecked.
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 is as expected; 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 in Next.js?

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

- **Module state is not shared between a page and a Route Handler in development**

  The confirmation compares the record with what your server pinned when it created the session. In a test on Next.js 16.4.6, a module-level `Map` filled by the page was empty in the Route Handler, and the same `Map` on `globalThis` held its entry. Keep that state in your database. On a serverless host memory is not shared at all.

- **A Server Component cannot set a cookie**

  If you keep the pinned state in a cookie, the page that creates the session cannot write it: Next.js answers `Cookies can only be modified in a Server Action or Route Handler`. Create the session in a Route Handler or a Server Action in that case, as the Vercel quickstart does.

- **The key must never get a NEXT_PUBLIC\_ name**

  Next.js puts every `NEXT_PUBLIC_` variable into the browser bundle. Name the key `ESIGNCOMPLY_API_KEY`, create the client in one file that starts with `import "server-only"`, and import that file from server code only. In the test, a `"use client"` page that imported it did not compile.

## Where are the Next.js quickstart and the API reference?

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

- Quickstart

  **[Next.js quickstart](https://esigncomply.com/docs/quickstart/nextjs)**

  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 build, file by file: the form, the server actions, the Supabase table, the webhook and the re-acceptance gate.

- 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 in Next.js?

The same record on every stack and platform. Your Next.js 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 in Next.js

### Is there an Esign Comply SDK for Next.js?

Yes. Next.js uses all three JavaScript packages: `esigncomply` on the server, and `@esigncomply/react` with `@esigncomply/browser` in client components. The hooks ship no visual components, so every element of the form is yours.

### Where do I create the session in Next.js?

In server code that holds the secret key: a Server Component, a Route Handler or a Server Action. The quickstart uses the signup page itself, a Server Component, so the form arrives with the client token in its props and the hooks attach as soon as it hydrates.

### Does it work with the App Router and React Server Components?

Yes. The quickstart was run on Next.js 16.4.6 with the App Router. The server package runs in Server Components and Route Handlers, and the hooks run in a file marked `"use client"`, because the browser SDK attaches inside an effect.

### Why did my confirm route lose the pinned versions in next dev?

Because module state set while a page renders is not visible to a Route Handler in development. A plain module-level Map was empty in the route when this was tested. Store the pinned versions in your database, or on `globalThis` for a first local run.

### Can a Server Action confirm the record?

Yes. A Server Action runs on the server and can read the record with the secret key before it creates the account. The quickstart uses a Route Handler so the conformance check can post a made-up record ID to it and see it refused.

### Other stacks

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

### Platforms used with Next.js

- [Vercel](https://esigncomply.com/vercel)
- [Supabase](https://esigncomply.com/supabase)
- [Netlify](https://esigncomply.com/netlify)

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

## Build the signup in your own Next.js app. Leave the record to us.

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

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

Next.js is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Next.js is from Next.js's documentation or from a test run, as marked, on November 23, 2026. `/nextjs.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.
