Add e-signatures and clickwrap to 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.
$npm install esigncomply @esigncomply/react @esigncomply/browser server-onlyFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
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} />; }
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]);
// 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 }); }
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, read on .- Server Componentapp/signup/page.tsx
- Client formapp/signup/signup-form.tsx
- Route Handlerapp/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.
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. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.
Pages for each AI toolAdd 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.mdWhat 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.
- 01
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
Mapfilled by the page was empty in the Route Handler, and the sameMaponglobalThisheld its entry. Keep that state in your database. On a serverless host memory is not shared at all. - 02
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. - 03
The key must never get a NEXT_PUBLIC_ name
Next.js puts every
NEXT_PUBLIC_variable into the browser bundle. Name the keyESIGNCOMPLY_API_KEY, create the client in one file that starts withimport "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.
- QuickstartNext.js quickstartStep by step, from install to your first sealed test record, with every file and the output of each step.Open
- ReferenceAPI referenceEvery endpoint, field and error code. Sessions, records and documents are the three this page uses.Open
- Long guideClickwrap in Next.js and SupabaseThe full build, file by file: the form, the server actions, the Supabase table, the webhook and the re-acceptance gate.Open
- GuideServer confirmationThe one place access is granted: what to compare, and the webhook that backs the check up.Open
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.
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, andGET /v1returns it again./records /{id} /receipt 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.
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.
Build the signup in your own Next.js app. Leave the record to us.
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 . /nextjs.md is this page as Markdown.