Add e-signatures and clickwrap to TanStack Start
To add e-signatures and clickwrap to TanStack Start, install esigncomply, @esigncomply/react and @esigncomply/browser. A server route creates the session with the secret key, the React hooks attach to your own checkbox and button, and a second server route confirms the record. Esign Comply seals each acceptance as an independent record 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/browserFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// src/routes/api/ceremony.ts import { createFileRoute } from '@tanstack/react-router' import { documentId, esc, pinned, signer } from '#/lib/esigncomply.server' // A server route: an HTTP endpoint in the route tree. Its handlers run on the server only. export const Route = createFileRoute('/api/ceremony')({ server: { handlers: { // Step 4: create the session with the secret key. The browser gets the client token only. POST: async ({ request }) => { // The page that runs the ceremony: the origin the browser reports, plus its path. const origin = request.headers.get('origin') ?? new URL(request.url).origin const { data: session, error } = await esc().sessions.create( { profile: process.env.ESIGNCOMPLY_PROFILE_ID!, signer, documents: [ { document: documentId('terms')!, version: 'current' }, { document: documentId('privacy')!, version: 'current' }, ], context: { url: `${origin}/signup`, locale: 'en-US', purpose: 'account_signup' }, }, { idempotencyKey: `signup-${signer.external_id}-${crypto.randomUUID()}` }, ) if (error) return Response.json({ error: error.code }, { status: 502 }) pinned.set( signer.external_id, session.documents.map((d) => d.version_id), ) return Response.json({ clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents }) }, }, }, })
// One session per page load. StrictMode runs effects twice in development, // so the request is kept in a ref and both runs share it. const request = useRef<Promise<CeremonySession> | null>(null) useEffect(() => { let mounted = true request.current ??= fetch('/api/ceremony', { method: 'POST' }).then((response) => response.json()) void request.current.then((value) => mounted && setSession(value)) return () => { mounted = false } }, []) const { ceremony, canComplete, error } = useCeremony({ clientToken: session?.clientToken, apiUrl: session?.apiUrl }) const [terms, privacy] = session?.documents ?? [] const tos = useDocument<HTMLAnchorElement>(ceremony, { versionId: terms?.version_id, mode: 'hyperlink' }) const notice = useDocument<HTMLAnchorElement>(ceremony, { versionId: privacy?.version_id, 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 || !tos.presented || !notice.presented) return void ceremony .observeAssent({ region: assentRef.current!, // notice, links, checkbox, button checkbox: checkboxRef.current!, submit: submitRef.current!, }) .then(() => setReady(true)) }, [ceremony, tos.presented, notice.presented])
// A server function: the handler runs on the server only, and the browser gets a stub that calls it. const getDocument = createServerFn({ method: 'GET' }) .validator((data: { slug: string; version?: string }) => data) .handler(async ({ data }) => { const id = documentId(data.slug) if (!id) throw notFound() const { data: content, error } = await esc().documents.versions.getContent(id, data.version || 'current') if (error || !content.html) throw notFound() return { versionId: content.version_id, html: content.html } }) // /legal/terms?v=dv_... loads one registered version. A loader runs on the server and in the browser, // so it holds no secret: it calls the server function. export const Route = createFileRoute('/legal/$slug')({ validateSearch: (search: Record<string, unknown>) => ({ v: typeof search.v === 'string' ? search.v : undefined }), loaderDeps: ({ search }) => ({ v: search.v }), loader: ({ params, deps }) => getDocument({ data: { slug: params.slug, version: deps.v } }), component: LegalDocument, })
// A file named *.server.ts: TanStack Start's import protection keeps it out of the browser bundle. // The environment is read when a request needs it, not when the module loads. let client: EsignComply | undefined export function esc() { return (client ??= new EsignComply(process.env.ESIGNCOMPLY_API_KEY)) }
How do you integrate Esign Comply with TanStack Start?
In TanStack Start all code runs on the server and in the browser unless it is constrained, and a route loader runs on both. The key stays in a *.server.ts file that only server route handlers and createServerFn handlers call. The page is React, so the @esigncomply/react hooks attach the ceremony.
TanStack Start is a full-stack React framework powered by TanStack Router.
Source: TanStack Start documentation, Overview, read on .- Server routesrc/routes/api/ceremony.ts
- Pagesrc/routes/signup.tsx
- Server functionsrc/routes/legal/$slug.tsx
- .server.tssrc/lib/esigncomply.server.ts
Run on 2026-11-26 with TanStack Start 1.169.7 (TanStack Router 1.170.46, React 19.3.1, Vite 8.3.8), in the app that npx @tanstack/cli create makes, with Nitro 3.0.261103-rc for the Node.js server, esigncomply 1.0.4, @esigncomply/react 1.0.1 and @esigncomply/browser 1.0.4 on Node.js 24.22.1, under vite dev (the conformance check from esigncomply 1.0.4) and as the built Node.js server (one ceremony), against the API in test mode.
What prompt adds Esign Comply clickwrap to a TanStack Start 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 TanStack Start, 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 TanStack Start 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/tanstack-start.md (the steps and the tested code for TanStack Start)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
TanStack Start facts
- Packages (the only ones that exist): esigncomply (server code, Node.js 20.19 or later), @esigncomply/react (hooks, React 18 or later) and @esigncomply/browser.
- All code in TanStack Start runs on the server and in the browser unless it is constrained. Keep the client and every read of the key in a file named *.server.ts, and call it only inside server route handlers and createServerFn handlers. The build fails when a component imports that file.
- A route loader runs on both sides, and what it returns is sent to the browser. Never read process.env in a loader and never return a secret from one. Read process.env inside handlers, not at module scope.
- Use server routes (createFileRoute with server.handlers) for POST /api/ceremony and POST /api/signup/confirm: they are HTTP endpoints. Use a server function for data a loader needs.
- Do not create the session in a loader: the router preloads a route when a link to it is hovered.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- The default client entry wraps the app in StrictMode, so effects run twice in development. Request the session once per mount, from a promise kept in a ref.
- TanStack Start has no session API. Keep the pinned version IDs in your database. Only for a first local run, a Map in the *.server.ts module works.
- The form is in the server HTML before the script loads: keep the checkbox disabled until observeAssent has resolved. Give the form its own text colour, so the links differ from the text around them by at least 3 to 1.
- For a Node.js server add nitro and its Vite plugin. The built server does not read .env.
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. src/routes/api/ceremony.ts, a server route (POST): 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. src/routes/legal/$slug.tsx: a createServerFn handler loads the registered version from esc.documents.versions.getContent, the route loader calls it, and the component renders it inside <article data-esc-document>, unmodified.
5. src/routes/signup.tsx: 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. src/routes/api/signup/confirm.ts, a server route (POST): 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 TanStack Start?
These are specific to TanStack Start. Each one was seen while the quickstart's code was run, or is in TanStack Start's own documentation.
- 01
A loader runs in the browser too, and what it returns is in the HTML
TanStack Start's documentation says route loaders run on both server and client. In the test on TanStack Start 1.169.7, hovering a link ran that route's loader in the browser before any click, and a value a loader returned on the server was in the page's HTML. The quickstart reads the key inside a
Source: TanStack Start documentation, Execution Model, read on .createServerFnhandler. - 02
The starter's text colour puts the document links under 3 to 1
The app
npx @tanstack/cli createmakes sets its text to#173a40. In the test, links in#0b57d0measured 1.92 to 1 against it, and the browser SDK reported aCR-05finding at Warn level. The quickstart's form sets its own text colour, and the same links measured 3.29 to 1. - 03
The default client entry runs the session request twice in development
TanStack Start's default client entry wraps the app in
StrictMode. In the test, afetchinuseEffectsent twoPOST /apifor one page load under/ceremony vite dev. With the request kept in a ref it sent one, undervite devand on the built server.
Where are the TanStack Start quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartTanStack Start 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
- 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 TanStack Start?
The same record on every stack and platform. Your TanStack Start 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 TanStack Start
Is there an Esign Comply SDK for TanStack Start?
Yes, the three JavaScript packages, and nothing specific to TanStack. Server routes and server functions use esigncomply, and the page uses the @esigncomply/react hooks over @esigncomply/browser. The hooks ship no components, so you build the form.
Where do I create the session in TanStack Start?
In a server route, for example src/routes, with esc.sessions.create inside its POST handler. The client lives in a *.server.ts file, and the route returns only the client token, the API URL and the pinned documents.
Should the endpoints be server routes or server functions?
Server routes for the session and the confirmation, because they are called by address: the page posts to them, and the conformance check posts a made-up record ID to the confirm route. A server function fits data that a loader needs, such as the text of a document page.
What keeps the key out of the browser bundle?
Import protection and the file name. In the test, vite build stopped with Import denied in client environment when a component imported the *.server.ts file. In the copy of a server route that vite dev sent to the browser, the handlers and the import were gone.
Does TanStack Start have a session helper for the pinned versions?
No. Its documentation says Start does not provide a session API. The quickstart keeps the pinned versions in a Map for a first run, and both server routes read the same Map under vite dev and in the built server. Use a table in your database in production.
Build the signup in your own TanStack Start app. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
TanStack Start is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about TanStack Start is from TanStack Start's documentation or from a test run, as marked, on . /tanstack-start.md is this page as Markdown.