# Add e-signatures and clickwrap to TanStack Start

> Add e-signatures and clickwrap to TanStack Start with esigncomply in server routes, a server function for the documents and the @esigncomply/react hooks.

Source: https://esigncomply.com/tanstack-start

Stack · 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.

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

`npm install esigncomply @esigncomply/react @esigncomply/browser`

[TanStack Start quickstart](https://esigncomply.com/docs/quickstart/tanstack-start)

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

Last updated November 26, 2026

Run in TanStack Start before publishing

**Server route**

`src/routes/api/ceremony.ts`

```ts
// 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 })
      },
    },
  },
})
```

**Page**

src/routes/signup.tsx (excerpt)

```tsx
// 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])
```

**Server function**

src/routes/legal/$slug.tsx (excerpt)

```tsx
// 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,
})
```

**.server.ts**

src/lib/esigncomply.server.ts (excerpt)

```ts
// 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))
}
```

Integrate with TanStack Start

## 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](https://tanstack.com/start/latest/docs/framework/react/overview), read on November 26, 2026.

[TanStack Start quickstart](https://esigncomply.com/docs/quickstart/tanstack-start) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in TanStack Start

- **Server route** · `src/routes/api/ceremony.ts`
- **Page** · `src/routes/signup.tsx`
- **Server function** · `src/routes/legal/$slug.tsx`
- **.server.ts** · `src/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.

Copy-paste prompt

## 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](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 TanStack Start

```
Add 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.md
```

3 things to watch

## What 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.

- **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 `createServerFn` handler.

  Source: [TanStack Start documentation, Execution Model](https://tanstack.com/start/latest/docs/framework/react/guide/execution-model), read on November 26, 2026.

- **The starter's text colour puts the document links under 3 to 1**

  The app `npx @tanstack/cli create` makes sets its text to `#173a40`. In the test, links in `#0b57d0` measured 1.92 to 1 against it, and the browser SDK reported a `CR-05` finding at Warn level. The quickstart's form sets its own text colour, and the same links measured 3.29 to 1.

- **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, a `fetch` in `useEffect` sent two `POST /api/ceremony` for one page load under `vite dev`. With the request kept in a ref it sent one, under `vite dev` and 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.

- Quickstart

  **[TanStack Start quickstart](https://esigncomply.com/docs/quickstart/tanstack-start)**

  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.

- 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 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](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 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/api/ceremony.ts`, 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.

### Other stacks

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

### Platforms used with TanStack Start

- [Vercel](https://esigncomply.com/vercel)
- [Netlify](https://esigncomply.com/netlify)
- [Railway](https://esigncomply.com/railway)

[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 TanStack Start app. Leave the record to us.

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

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 November 26, 2026. `/tanstack-start.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.
