Add e-signatures and clickwrap to Astro
To add e-signatures and clickwrap to Astro, install esigncomply, @esigncomply/browser and an adapter. An endpoint rendered on demand creates the session with the secret key from astro:env/server, the static signup page attaches the browser SDK in a client script, and a second endpoint 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.
$npx astro add node && npm install esigncomply @esigncomply/browserFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// src/pages/api/ceremony.ts import type { APIRoute } from "astro"; import { ESIGNCOMPLY_PROFILE_ID } from "astro:env/server"; import { DOCUMENTS, esc, signer } from "../../lib/esigncomply"; // Rendered on demand. Without this line Astro prerenders the route when it builds the site. export const prerender = false; // Step 4: create the session with the secret key. The browser gets the client token only. export const POST: APIRoute = async ({ request, url, session }) => { // The page that runs the ceremony: the origin the browser reports, plus its path. const origin = request.headers.get("origin") ?? url.origin; const { data: created, error } = await esc.sessions.create( { profile: 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}-${crypto.randomUUID()}` }, ); if (error) return Response.json({ error: error.code }, { status: 502 }); // The Astro session lives on the server. The browser holds only its ID, in a cookie. session?.set("pinnedVersions", created.documents.map((d) => d.version_id)); return Response.json({ clientToken: created.client_token, apiUrl: created.api_url, documents: created.documents }); };
// One session per page load. async function start() { // Your endpoint creates the session and returns { clientToken, apiUrl, documents }. Never the secret key. const response = await fetch("/api/ceremony", { method: "POST" }); if (!response.ok) throw new Error("We could not start the signup. Reload the page to try again."); const { clientToken, apiUrl, documents } = await response.json(); ceremony = await EsignComply.attach({ clientToken, apiUrl }); ceremony.on("change", ({ remainingSteps }) => { submit.disabled = remainingSteps.some((step) => step !== "signature.applied"); }); // Point each link at the exact version this session pinned, then report it. const links = [document.querySelector<HTMLAnchorElement>("#tos-link")!, document.querySelector<HTMLAnchorElement>("#privacy-link")!]; for (const [i, link] of links.entries()) { link.search = "?v=" + documents[i].version_id; await ceremony.presentDocument({ versionId: documents[i].version_id, mode: "hyperlink", link }); } await ceremony.observeAssent({ region: document.querySelector("#assent")!, // notice, links, checkbox, button checkbox: agree, submit, }); agree.disabled = false; // the SDK watches the box from here on. Only the user ticks it. } start().catch((error) => (message.textContent = error.message));
export default defineConfig({ // Routes rendered on demand need an adapter. This one builds a Node.js server. adapter: node({ mode: "standalone" }), env: { schema: { // Server and secret: importable from astro:env/server only, read when the server runs, in no bundle. ESIGNCOMPLY_API_KEY: envField.string(secret), ESIGNCOMPLY_PROFILE_ID: envField.string(secret), ESIGNCOMPLY_TERMS_ID: envField.string(secret), ESIGNCOMPLY_PRIVACY_ID: envField.string(secret), // Optional: the SDK picks the API host from the key when this is not set. ESIGNCOMPLY_API_URL: envField.string({ ...secret, optional: true }), // "true" in production only. ESIGNCOMPLY_LIVE: envField.boolean({ ...secret, default: false }), }, }, });
// src/pages/api/signup/confirm.ts import type { APIRoute } from "astro"; import { LIVE, SEALED, esc, signer } from "../../../lib/esigncomply"; export const prerender = false; // Step 6: confirm the record with the secret key before the account exists. export const POST: APIRoute = async ({ request, session }) => { const body = await request.json().catch(() => ({})); // an empty or malformed body is refused below const { data: record, error } = await esc.records.get(String(body.recordId)); const pinned: string[] = (await session?.get("pinnedVersions")) ?? []; const confirmed = !error && 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([...pinned].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 }); };
How do you integrate Esign Comply with Astro?
Astro builds static HTML unless a route opts out. The signup page stays static, and the two endpoints and the document page carry export const prerender = false, which needs an adapter. The key reaches them through astro:env/server, and a plain <script> tag on the page is bundled with the browser SDK inside.
Astro is the web framework for building content-driven websites like blogs, marketing, and e-commerce.
Source: Astro documentation, Why Astro?, read on .- Endpointsrc/pages/api/ceremony.ts
- Client scriptsrc/pages/signup.astro
- Secret keyastro.config.mjs
- Confirm endpointsrc/pages/api/signup/confirm.ts
Run on 2026-11-26 with Astro 7.4.13, @astrojs/node 11.1.14 and Vite 8.3.8, esigncomply 1.0.4 and @esigncomply/browser 1.0.4 on Node.js 24.22.1, under astro 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 Astro 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 Astro, 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 Astro 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/astro.md (the steps and the tested code for Astro)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
Astro facts
- Packages (the only ones that exist): esigncomply (server code, Node.js 20.19 or later) and @esigncomply/browser (the page). There is no Astro integration for Esign Comply.
- Astro prerenders every route unless the route says otherwise. Each endpoint and page that calls the API needs export const prerender = false, and the project needs an adapter: npx astro add node.
- Declare ESIGNCOMPLY_API_KEY in env.schema with envField.string({ context: "server", access: "secret" }) and import it from astro:env/server, in server code only. Pass it to new EsignComply(key): under astro dev the values of .env are not in process.env. Never give it a PUBLIC_ name.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- Put the browser code in a plain <script> tag of the page. Astro bundles it and resolves the @esigncomply/browser import. Never import astro:env/server or the server module there.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.
- Print the document HTML with set:html. An expression in braces is escaped.
- Keep the pinned version IDs in the Astro session (context.session in an endpoint). It is stored on the server.
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/pages/api/ceremony.ts (POST, prerender = false): create the session with esc.sessions.create and an Idempotency-Key, save the pinned version IDs in the Astro session, and return only clientToken, apiUrl and documents.
4. src/pages/legal/[slug].astro (prerender = false): load the registered version from esc.documents.versions.getContent and render it inside <article data-esc-document> with set:html, unmodified.
5. src/pages/signup.astro: in the page's <script>, EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then ceremony.complete() in the submit handler. The checkbox has no checked attribute.
6. src/pages/api/signup/confirm.ts (POST, prerender = false): 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:4321/signup --callback http://localhost:4321/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 Astro?
These are specific to Astro. Each one was seen while the quickstart's code was run, or is in Astro's own documentation.
- 01
An endpoint without prerender = false is built once, at build time
Astro prerenders every route by default. In a test on Astro 7.4.13, a
Source: Astro documentation, On-demand rendering, read on .POSTendpoint with noexport const prerender = falsestill answered underastro dev, with a warning in the log. Afterastro buildit was a static file, and the built server answered aPOSTto it with status200and the HTML of the 404 page. The handler never ran. - 02
Under astro dev, the key from .env is not in process.env
The
Source: Astro documentation, Using environment variables, read on .esigncomplyclient readsESIGNCOMPLY_API_KEYfromprocess.envwhen it gets no argument. Underastro devthe key from.envwas inastro:env/serverand not inprocess.env, and a client created with no argument answeredmissing_api_key. Declare the key inenv.schemaas a server secret and pass it to the client. - 03
node dist/server/entry.mjs starts without your variables
Astro's documentation says neither Astro nor the adapter loads environment variables for you at runtime. In the test, the built server started with no variables served the static signup page and answered the session request with
Source: Astro documentation, @astrojs/node, read on .500andEnvInvalidVariables. Started withnode --env-file=.env, the same build sealed a record.
Where are the Astro quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartAstro 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 Astro?
The same record on every stack and platform. Your Astro 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 Astro
Is there an Esign Comply SDK for Astro?
Yes, the two JavaScript packages, and no Astro integration. Endpoints use esigncomply, and the page imports @esigncomply/browser in a plain <script> tag, which Astro bundles. The browser SDK is headless, so it attaches to the markup you wrote in the .astro file.
Where do I create the session in Astro?
In an endpoint rendered on demand, for example src/pages, with esc.sessions.create. The file exports prerender = false, imports the key from astro:env/server, and returns only the client token, the API URL and the pinned documents.
Can the signup page stay a static page?
Yes. The quickstart builds it once as static HTML, and its script asks an endpoint for a session on each page load. Only the two endpoints and the document page are rendered on demand. The conformance check passed on that setup with Astro 7.4.13.
What does Astro do when a client script imports astro:env/server?
It stops the build. astro build ended with ServerOnlyModule and said the module is only available server-side. Under astro dev the page loaded and the browser's request for the module was answered 500. After a build, no file under dist held the key.
Does the Astro session put the pinned versions in the cookie?
No. The cookie holds an ID only. In the test run it was named astro-session, held 36 characters and was marked HttpOnly and SameSite=Lax, and the Node adapter kept the version IDs in a file on the server. A real record ID sent without the cookie was refused with 409.
Build the signup in your own Astro project. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
Astro is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Astro is from Astro's documentation or from a test run, as marked, on . /astro.md is this page as Markdown.