# Add e-signatures and clickwrap with Angular

> Build a signup clickwrap in Angular with esigncomply in the Express server of ng new --ssr and the browser SDK in afterNextRender, then seal a test record.

Source: https://esigncomply.com/docs/quickstart/angular

Last updated November 26, 2026

To add e-signatures and clickwrap with Angular, install `esigncomply` and `@esigncomply/browser`. The Express server that `ng new --ssr` creates holds the secret key and carries the session route, the confirm route and the document pages. A component attaches the browser SDK to your own checkbox in `afterNextRender`. Esign Comply seals each acceptance as an independent record.

Follow the steps and each signature your app records is a valid electronic signature under the ESIGN Act, state UETA laws and New York's ESRA, and your clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

Paste this prompt into Cursor, Claude Code or another AI coding tool to have it build the same integration:

```text copy="Copy prompt" open="cursor"
Add Esign Comply clickwrap to my Angular 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/angular.md (the steps and the tested code for Angular)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Angular facts
- Packages (the only ones that exist): esigncomply (server code, Node.js 20.19 or later) and @esigncomply/browser (the component). There is no Angular package.
- The app needs server-side rendering (ng new --ssr, or ng add @angular/ssr): its Express file src/server.ts is the only place for the secret key. Put the routes in a file that src/server.ts imports, and register them before the Angular handler. Never import that file from anything under src/app.
- The Angular CLI does not read .env. Start ng serve through node --env-file=.env, and add .env to .gitignore: ng new does not list it. Never print the key.
- Never read process.env in a component. The class also runs on the server, and with prerendering it runs at build time: the value ends up in a static HTML file.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- Call fetch and EsignComply.attach inside afterNextRender only. After you set the signal that feeds the two link addresses, wait for the next render before presentDocument.
- The form is in the server HTML before the script loads. Keep the checkbox disabled until observeAssent has resolved.
- The built server answers 400 to a host that is not in security.allowedHosts (angular.json) or in NG_ALLOWED_HOSTS.

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/api.ts, an Express Router that src/server.ts mounts: POST /api/ceremony creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in server-owned state, and returns only clientToken, apiUrl and documents.
4. GET /legal/:slug in the same router renders the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. src/app/signup/signup.ts, a component on the route /signup: in afterNextRender, EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }) with viewChild elements, then ceremony.complete() in the submit handler. The checkbox has no checked attribute and no binding that ticks it.
6. POST /api/signup/confirm in the router reads the record with esc.records.get and requires: 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:4200/signup --callback http://localhost:4200/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
```

The rest of this page is the same integration by hand, in eight steps.

## Before you start

- A test API key. [Create an account](https://esigncomply.com/signup) with your email, no card, then choose **Create test key** in the dashboard. The key is shown once and starts with `esc_test_`. An AI agent with an agent token creates it with `POST /v1/agent/api-keys`: see the [agent account API](https://esigncomply.com/docs/api/agent.md).
- Nothing else from Esign Comply. Test mode works on `localhost` with no card and no domain, and the Free plan includes it in full.
- An Angular app with server-side rendering. To start one: `npx @angular/cli@latest new my-app --ssr`. In an existing app: `ng add @angular/ssr`. This page was run on Angular 22.3.0, in the app that command creates, with CSS for the styles.
- Node.js 22.22.3 or later on the 22 line, or 24.15 or later: Angular 22.3.0 declares both in its `engines` field. The `esigncomply` package needs 20.19 or later. This page was run on Node.js 24.22.1.
- `curl` and `jq` for steps 2 and 3.

## Step 1. Install

Install the server package for the routes and the browser SDK for the component:

```bash
npm install esigncomply @esigncomply/browser
```

There is no Angular package to add. The browser SDK is headless: you write the template, and it observes it. Express is already in the project, because `ng new --ssr` installs it for `src/server.ts`.

## Step 2. Set the key

Put the key in `.env` in the project folder, and keep the file out of Git. The `.gitignore` that `ng new` writes does not list it:

```bash
# .env (never commit this file)
ESIGNCOMPLY_API_KEY=esc_test_us_...
```

```bash
printf '.env\n' >> .gitignore
```

The Angular CLI does not read `.env`. With the file in place and `ng serve` started as it is, the session route of step 4 answered `502` with `missing_api_key` when this was tried. Node.js can load the file itself, so change the `start` script in `package.json` to run the CLI through `node --env-file=.env`:

```json file="package.json"
{
  "name": "my-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node --env-file=.env node_modules/@angular/cli/bin/ng.js serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "serve:ssr:my-app": "node dist/my-app/server/server.mjs"
  },
  "private": true,
  "packageManager": "npm@11.19.1",
  "dependencies": {
    "@angular/common": "^22.3.0",
    "@angular/compiler": "^22.3.0",
    "@angular/core": "^22.3.0",
    "@angular/forms": "^22.3.0",
    "@angular/platform-browser": "^22.3.0",
    "@angular/platform-server": "^22.3.0",
    "@angular/router": "^22.3.0",
    "@angular/ssr": "^22.3.0",
    "@esigncomply/browser": "^1.0.4",
    "esigncomply": "^1.0.4",
    "express": "^5.1.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0"
  },
  "devDependencies": {
    "@angular/build": "^22.3.0",
    "@angular/cli": "^22.3.0",
    "@angular/compiler-cli": "^22.3.0",
    "@types/express": "^5.0.1",
    "@types/node": "^22.12.0",
    "jsdom": "^31.0.0",
    "prettier": "^3.8.1",
    "typescript": "~6.0.2",
    "vitest": "^5.0.0"
  }
}
```

Only the `start` line differs from what `ng new` wrote. The flag has to be on the command line: set through `NODE_OPTIONS`, Node.js 24.22.1 stopped with `--env-file= is not allowed in NODE_OPTIONS`. The `serve:ssr:my-app` script stays as it is, because in production the variables come from the host.

Load the file into your shell for the commands in steps 2, 3 and 7, then check that the key works:

```bash
set -a; . ./.env; set +a
curl -s ${ESIGNCOMPLY_API_URL:-https://esigncomply.com/v1}/usage \
  -H "Authorization: Bearer $ESIGNCOMPLY_API_KEY" | jq '{plan_name, test_events}'
```

```json
{
  "plan_name": "Free",
  "test_events": {
    "used_this_month": 0,
    "quota_per_month": 500
  }
}
```

A `401` means the key is wrong or revoked: see [`invalid_api_key`](https://esigncomply.com/docs/api/errors.md#invalid_api_key). The rules for handling keys are in [/auth.md](https://esigncomply.com/auth.md).

## Step 3. Register a document version

Every record pins the exact version of each document by hash, so the documents are registered first. This block registers a Terms of Service and a Privacy Notice with one version each, and creates a profile: the Federal pack, a checkbox with a button, level L1. It is the same for every stack and needs `curl` and `jq`.

```bash
ESC=${ESIGNCOMPLY_API_URL:-https://esigncomply.com/v1}
KEY="Authorization: Bearer $ESIGNCOMPLY_API_KEY"
JSON="Content-Type: application/json"

# Two sample documents, one version each.
TERMS=$(curl -s $ESC/documents -H "$KEY" -H "$JSON" \
  -d '{"name":"Terms of Service","type":"terms"}' | jq -r .id); sleep 1
curl -s $ESC/documents/$TERMS/versions -H "$KEY" -H "$JSON" \
  -d '{"version_label":"1","language":"en","content":{"format":"markdown","text":"# Terms of Service\n\nThese are sample terms for a test."},"material_change":true}' \
  | jq -r .id; sleep 1
PRIVACY=$(curl -s $ESC/documents -H "$KEY" -H "$JSON" \
  -d '{"name":"Privacy Notice","type":"privacy_notice"}' | jq -r .id); sleep 1
curl -s $ESC/documents/$PRIVACY/versions -H "$KEY" -H "$JSON" \
  -d '{"version_label":"1","language":"en","content":{"format":"markdown","text":"# Privacy Notice\n\nThis is a sample privacy notice for a test."}}' \
  | jq -r .id; sleep 1

# A profile: Federal pack, checkbox plus button, L1.
PROFILE=$(curl -s $ESC/profiles -H "$KEY" -H "$JSON" \
  -d '{"name":"Signup","jurisdictions":["US-FED"],"method":"checkbox","assurance_level":"L1"}' | jq -r .id)

printf 'ESIGNCOMPLY_PROFILE_ID=%s\nESIGNCOMPLY_TERMS_ID=%s\nESIGNCOMPLY_PRIVACY_ID=%s\n' "$PROFILE" "$TERMS" "$PRIVACY"
```

It prints the two version IDs, then three lines with your own IDs:

```text
dv_YiWs9cmWoVSGp7ALPeZS
dv_bAYeA7QigKUH0iLhPpV7
ESIGNCOMPLY_PROFILE_ID=prof_SPVEgBT8a8Ror3mJ8M99
ESIGNCOMPLY_TERMS_ID=doc_bDgYFndAoC8tkeYibAVy
ESIGNCOMPLY_PRIVACY_ID=doc_mb2hnWKS0Qa7SKtucDW9
```

Add the three lines to `.env`. The pauses keep the script under the Free plan's 2 requests per second. Keep the names `Terms of Service` and `Privacy Notice`: the notice on your page names each document by its registered name, and rule [CR-02](https://esigncomply.com/docs/conformance.md#cr-02) checks that it does. With your own documents, publish the text you already have and change the notice to match. See [Documents](https://esigncomply.com/docs/api/documents.md) and [Profiles](https://esigncomply.com/docs/api/profiles.md).

## Step 4. Create a session on the server

An Angular app with server-side rendering has a server of its own: `src/server.ts`, an Express app. It is the only part of the project that never reaches a browser, so the secret key lives there. Put the routes in a file beside it, `src/api.ts`:

```ts file="src/api.ts"
// src/api.ts
import { randomUUID } from 'node:crypto';
import { Router, json } from 'express';
import { EsignComply } from 'esigncomply';

// Server only: src/server.ts imports this file, and nothing under src/app may.
// The SDK reads ESIGNCOMPLY_API_KEY and ESIGNCOMPLY_API_URL from process.env itself.
const esc = new EsignComply();

// The signer. In your app this is the signed-in user, or the account you are about to create.
const signer = {
  external_id: 'user_7c1d',
  email: 'dana@example.org',
  name: 'Dana Whitfield',
  class: 'consumer',
  country: 'US',
  region: 'US-CA',
} as const;

const DOCUMENTS: Record<string, string | undefined> = {
  terms: process.env['ESIGNCOMPLY_TERMS_ID'],
  privacy: process.env['ESIGNCOMPLY_PRIVACY_ID'],
};
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';

// Signer ID -> the version IDs this server pinned. Use a table in your database in production.
const pinned = new Map<string, string[]>();

export const api = Router();

// Step 4: create the session with the secret key. The browser gets the client token only.
api.post('/api/ceremony', async (req, res) => {
  // The page that runs the ceremony: the origin the browser reports, plus its path.
  const origin = req.get('origin') ?? `${req.protocol}://${req.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 void res.status(502).json({ error: error.code });

  pinned.set(
    signer.external_id,
    session.documents.map((d) => d.version_id),
  );
  res.json({ clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
});

// The document pages: each one renders a registered version, unmodified.
api.get('/legal/:slug', async (req, res) => {
  const documentId = DOCUMENTS[req.params.slug];
  if (!documentId) return void res.status(404).json({ error: 'not_found' });

  const version = typeof req.query['v'] === 'string' && req.query['v'] ? req.query['v'] : 'current';
  const { data, error } = await esc.documents.versions.getContent(documentId, version);
  if (error || !data.html) return void res.status(404).json({ error: error?.code ?? 'not_found' });

  res
    .type('html')
    .send(`<!doctype html><meta charset="utf-8"><article data-esc-document="${data.version_id}">${data.html}</article>`);
});

// Step 6: confirm the record with the secret key before the account exists.
api.post('/api/signup/confirm', json(), async (req, res) => {
  const { data: record, error } = await esc.records.get(String(req.body?.recordId));

  const expected = [...(pinned.get(signer.external_id) ?? [])].sort();
  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(expected);

  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : 'refused');
  if (!confirmed) return void res.status(409).json({ confirmed: false });
  // Only now create the account, and store record.id and record.receipt with it.
  res.json({ confirmed: true, recordId: record.id });
});
```

The client takes no argument. Node.js was started with `--env-file`, so the key is in `process.env`, which is where the SDK looks. The signer is a fixed test person here. In your app it is the signed-in user or the account you are about to create.

Then mount the router in `src/server.ts`, in the place where `ng new` left a comment for API endpoints, before the static files and the Angular handler:

```ts file="src/server.ts"
import {
  AngularNodeAppEngine,
  createNodeRequestHandler,
  isMainModule,
  writeResponseToNodeResponse,
} from '@angular/ssr/node';
import express from 'express';
import { join } from 'node:path';
import { api } from './api';

const browserDistFolder = join(import.meta.dirname, '../browser');

const app = express();
const angularApp = new AngularNodeAppEngine();

// The session route, the confirm route and the document pages. They hold the secret key.
app.use(api);

/**
 * Serve static files from /browser
 */
app.use(
  express.static(browserDistFolder, {
    maxAge: '1y',
    index: false,
    redirect: false,
  }),
);

/**
 * Handle all other requests by rendering the Angular application.
 */
app.use((req, res, next) => {
  angularApp
    .handle(req)
    .then((response) =>
      response ? writeResponseToNodeResponse(response, res) : next(),
    )
    .catch(next);
});

/**
 * Start the server if this module is the main entry point, or it is ran via PM2.
 * The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
 */
if (isMainModule(import.meta.url) || process.env['pm_id']) {
  const port = process.env['PORT'] || 4000;
  app.listen(port, (error) => {
    if (error) {
      throw error;
    }

    console.log(`Node Express server listening on http://localhost:${port}`);
  });
}

/**
 * Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
 */
export const reqHandler = createNodeRequestHandler(app);
```

Two lines were added to that file: the import and `app.use(api)`. Two things here are specific to Angular. `ng serve` runs this same file, through the `reqHandler` it exports, so the three routes answered under `ng serve` with no proxy and no second process. And the `pinned` Map is plain server memory that both routes share, because they sit in one module. Under `ng serve` an edit that changed the build output emptied it, whether the edit was in `src/api.ts` or in a component. Replace the Map with a table in your database before you run more than one process.

## Step 5. Attach the ceremony in the browser

The browser SDK renders nothing. It observes the checkbox, the notice, the links and the button of your own template, and reports each step from the signer's browser straight to Esign Comply. The form is one component, `src/app/signup/signup.ts`:

```ts file="src/app/signup/signup.ts"
// src/app/signup/signup.ts
import { Component, DestroyRef, ElementRef, Injector, afterNextRender, inject, signal, viewChild } from '@angular/core';
import { EsignComply, type Ceremony } from '@esigncomply/browser';

@Component({
  selector: 'app-signup',
  template: `
    <form class="signup" (submit)="onSubmit($event)">
      <h1>Create account</h1>
      <div #assent>
        <!-- The box is in the server HTML, so it stays disabled until the SDK watches it. Only the user changes it. -->
        <label><input #checkbox type="checkbox" [disabled]="!ready()" /> I agree to the Terms of Service and Privacy Notice</label>
        <p>
          By checking the box and clicking Create account, you agree to the
          <a #termsLink [href]="'/legal/terms?v=' + (versions()[0] ?? '')">Terms of Service</a> and acknowledge the
          <a #privacyLink [href]="'/legal/privacy?v=' + (versions()[1] ?? '')">Privacy Notice</a>.
        </p>
        <button #submit type="submit" [disabled]="!canComplete()">Create account</button>
      </div>
      <p role="alert">{{ message() }}</p>
    </form>
  `,
  styles: `
    .signup { font: 16px/1.5 system-ui, sans-serif; max-width: 480px; margin: 48px auto; padding: 0 20px; }
    /* Document links are underlined and differ from the text around them by at least 3 to 1 (rule CR-05). */
    a { color: #0b57d0; text-decoration: underline; }
    button { font: inherit; padding: 10px 16px; }
  `,
})
export class Signup {
  private readonly assent = viewChild.required<ElementRef<HTMLDivElement>>('assent');
  private readonly checkbox = viewChild.required<ElementRef<HTMLInputElement>>('checkbox');
  private readonly submit = viewChild.required<ElementRef<HTMLButtonElement>>('submit');
  private readonly termsLink = viewChild.required<ElementRef<HTMLAnchorElement>>('termsLink');
  private readonly privacyLink = viewChild.required<ElementRef<HTMLAnchorElement>>('privacyLink');
  private readonly injector = inject(Injector);

  protected readonly versions = signal<string[]>([]); // the version IDs this session pinned, for the two links
  protected readonly ready = signal(false); // true once the SDK observes the checkbox
  protected readonly canComplete = signal(false);
  protected readonly message = signal('');
  private ceremony: Ceremony | undefined;

  constructor() {
    // This class also runs on the server while Angular renders the page.
    // afterNextRender runs in the browser only, once, when the form is in the DOM: one session per page load.
    afterNextRender(() => void this.start());
    inject(DestroyRef).onDestroy(() => this.ceremony?.destroy());
  }

  private async start() {
    try {
      // Your server 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 session = await response.json();

      const ceremony = await EsignComply.attach({ clientToken: session.clientToken, apiUrl: session.apiUrl });
      this.ceremony = ceremony;
      ceremony.on('change', ({ remainingSteps }) => {
        this.canComplete.set(!remainingSteps.some((step) => step !== 'signature.applied'));
      });

      // Point each link at the exact version this session pinned, wait for Angular to update the DOM, then report it.
      this.versions.set(session.documents.map((document: { version_id: string }) => document.version_id));
      await new Promise<void>((resolve) => afterNextRender(() => resolve(), { injector: this.injector }));
      const [terms, privacy] = this.versions();
      await ceremony.presentDocument({ versionId: terms, mode: 'hyperlink', link: this.termsLink().nativeElement });
      await ceremony.presentDocument({ versionId: privacy, mode: 'hyperlink', link: this.privacyLink().nativeElement });
      await ceremony.observeAssent({
        region: this.assent().nativeElement, // notice, links, checkbox, button
        checkbox: this.checkbox().nativeElement,
        submit: this.submit().nativeElement,
      });
      this.ready.set(true);
    } catch (error) {
      this.message.set(error instanceof Error ? error.message : 'Something went wrong.');
    }
  }

  protected async onSubmit(event: Event) {
    event.preventDefault();
    if (!this.ceremony) return;
    try {
      const result = await this.ceremony.complete(); // the signing act, from the signer's own click
      // The result came to the browser. Your server confirms the record before anything is granted.
      const confirmed = await fetch('/api/signup/confirm', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ recordId: result.recordId }),
      });
      this.message.set(
        confirmed.ok
          ? `Account created. Record ${result.recordId}`
          : 'We could not confirm whether your acceptance was recorded. Please wait while we check.',
      );
    } catch (error) {
      this.message.set(error instanceof Error ? error.message : 'Something went wrong.');
    }
  }
}
```

Give it a route:

```ts file="src/app/app.routes.ts"
// src/app/app.routes.ts
import { Routes } from '@angular/router';
import { Signup } from './signup/signup';

export const routes: Routes = [{ path: 'signup', component: Signup, title: 'Create account' }];
```

And replace the placeholder page in `src/app/app.html` with the outlet the router renders into:

```html file="src/app/app.html"
<router-outlet />
```

Start the app and open [http://localhost:4200/signup](http://localhost:4200/signup):

```bash
npm start
```

The button stays disabled until the box is ticked. Tick it, click **Create account**, and the page shows a line such as:

```text
Account created. Record rec_U1Ex7fvNvTkFikaiYF4L
```

Three details matter, and each one was seen in the test run.

Everything that needs the browser sits in `afterNextRender`, because the class also runs on the server while Angular renders the page. With `start()` called straight from the constructor, the server ran the request too, and the HTML it sent carried `Failed to parse URL from /api/ceremony` in the alert paragraph. One page load sent one `POST /api/ceremony` when this was counted, under `ng serve` and on the built server.

The code waits for a render after `versions.set(...)`. The app `ng new` creates has no zone.js, and a signal does not change the DOM at once. Without the wait, the SDK requested the first link as `/legal/terms?v=`, with no version ID.

The checkbox is disabled until the SDK observes it. Angular sends the form as HTML before the script loads, and hydration keeps the same elements. In a test with the script held back, a box ticked in that HTML stayed ticked, and the SDK reported a finding for [CR-01](https://esigncomply.com/docs/conformance.md#cr-01) at Block level: the control had been used before it was watched. With `[disabled]="!ready()"` the box cannot be used that early. It has no `checked` attribute and no binding that ticks it: only the user changes it.

## Step 6. Confirm the record on the server

The result of `ceremony.complete()` was delivered to the browser, so your server does not trust it. `POST /api/signup/confirm` in `src/api.ts` reads the record with the secret key and grants access only when four things hold: the status is `recorded`, `timestamped` or `anchored`; `livemode` is what this deployment expects; the signer is the one this server created the session for; and the document versions are exactly the ones it pinned. This step is never optional.

The server prints one line for each confirmation, in the terminal that runs `npm start`:

```text
confirmed rec_U1Ex7fvNvTkFikaiYF4L (recorded)
```

A record ID that was made up is refused with status `409`:

```bash
curl -s -X POST http://localhost:4200/api/signup/confirm \
  -H "Content-Type: application/json" -d '{"recordId":"rec_made_up"}'
```

```json
{"confirmed":false}
```

See [Server confirmation](https://esigncomply.com/docs/guides/server-confirmation.md) for the webhook that backs this route up when the browser closes early.

## Step 7. Check the result

Open the dashboard and choose **Records**. The test record is there with what was observed, what was asserted, and its evidence report, watermarked TEST.

Then run the conformance check against the page. It opens the page in headless Chromium at three window sizes, signs as a visitor would, and tries four things that must be refused. One of them posts a made-up record ID to your confirm route.

```bash
npm install --save-dev playwright
npx playwright install chromium
npx esigncomply check --url http://localhost:4200/signup --callback http://localhost:4200/api/signup/confirm
```

The report for this page's code, shortened:

```text
Violations that must be refused
  REFUSED   Submit with the checkbox untouched      No record was made.
  REFUSED   Completion from another origin          The API answered 403 domain_mismatch.
  REFUSED   Programmatic click                      No record was made.
  REFUSED   Forged success posted to your callback  http://localhost:4200/api/signup/confirm answered 409.

Ceremonies
  390x844    record rec_U1Ex7fvNvTkFikaiYF4L  session ses_jwWrpRmKPYgQ1G7uGiLU, 5 events
  768x1024   record rec_WDscFuvfhF4jnifYGuLv  session ses_TjLjQS7dvtbZhhiwao50, 5 events
  1440x900   record rec_H6vyssEBAXfMyatNf21S  session ses_4tcF9eLZWo8Y4GeySiF8, 5 events

Summary: 0 block, 0 warn, 27 pass.
```

This run was made under `ng serve`. The checker waits for a checkbox that starts disabled, so the form of step 5 needs no change for it.

Fix every finding marked `block` and read every finding marked `warn`. Each one names the rule the screen missed, the measurement and the fix. In test mode a finding never stops a record from being sealed, so read the report. The rules are on [Conformance rules](https://esigncomply.com/docs/conformance.md), and every flag of the command is on the [CLI page](https://esigncomply.com/docs/sdk/cli.md).

## Step 8. Go live

Going live takes three steps on the Esign Comply side. There is no plan to choose and no checkout: the Free plan records 10 live signatures a month.

1. Register your production domain and verify it. See [Register a domain](https://esigncomply.com/docs/guides/domains.md).
2. Add your organization's legal name, country and address under **Go live** in the dashboard.
3. Create a live key. It is shown once and starts with `esc_live_`.

Test and live share nothing, so create the documents and the profile again with the live key, or copy them to live from the dashboard, and use the live IDs in production.

Then switch the app over:

- Set the live key as `ESIGNCOMPLY_API_KEY` and set `ESIGNCOMPLY_LIVE=true` in production only. From then on the confirm route refuses every test record there.
- Allow your host. `ng new` writes `"allowedHosts": []` under `security` in `angular.json`, and the built server answers every page with `400` until the host is listed there or in the `NG_ALLOWED_HOSTS` variable. In the test run the built server answered `/signup` with `Header "host" with value "localhost:4301" is not allowed`. The three Express routes are mounted before that check and answered anyway.
- Build with `ng build` and start the server with `npm run serve:ssr:my-app`, which runs `node dist/my-app/server/server.mjs` on the port in `PORT`, or 4000. Give the process its variables: it does not read `.env`. In the test run, `NG_ALLOWED_HOSTS=localhost node --env-file=.env dist/my-app/server/server.mjs` sealed a record, and the page showed `Account created. Record rec_N2mEk2t18ysmM7BvVNV6`.
- Replace the `pinned` Map with a table in your database, and store `record.id` and `record.receipt` beside the user.

In live mode `context.url` must be inside your registered domain, and browser calls are accepted only from it. By default a live signature with a finding at Block level is recorded and you are told at once which rule failed. Turn on blocking, on the dashboard's Conformance page, and it is refused before it is sealed. Run the check from step 7 until no finding is at Block level before you switch keys.

## Troubleshooting

- **`400` and `Header "host" with value "..." is not allowed`.** The built server does not know the host the page was opened on. Add it to `security.allowedHosts` in `angular.json` and build again, or set `NG_ALLOWED_HOSTS` where the server runs. `ng serve` makes no such check on `localhost`, so this shows up only after the build. With `NG_ALLOWED_HOSTS=localhost`, the address `127.0.0.1` was still answered `400`.
- **`missing_api_key` from `/api/ceremony`.** The server process has no `ESIGNCOMPLY_API_KEY`, and the route answers `502`. The Angular CLI does not read `.env`: start it with `npm start` and the script of step 2, not with `ng serve` alone. The built server needs the variable in its environment. See [`missing_api_key`](https://esigncomply.com/docs/api/errors.md#missing_api_key).
- **`domain_mismatch` when the page loads.** The page was opened from a host that is not on the test allowlist, for example your machine's LAN address from `ng serve --host`. Test keys work on `localhost` and `127.0.0.1` at any port. Add other hosts under Domains in the dashboard. See [`domain_mismatch`](https://esigncomply.com/docs/api/errors.md#domain_mismatch).
- **`429` when the confirm route reads the record.** The route needs no retry loop: the `esigncomply` package waits for the time in `Retry-After` and tries again, up to twice. In the test, four confirmations sent at once for one record all answered `200` on the built server, two of them a second later than the others. Four reads sent at once through the package showed why: two got `429` with `Retry-After: 1` and passed on the next attempt. See [`rate_limit_exceeded`](https://esigncomply.com/docs/api/errors.md#rate_limit_exceeded) and [Retries and timeouts](https://esigncomply.com/docs/sdk/node.md#retries-and-timeouts).

## Questions about the Angular quickstart

### Why does the form start the ceremony in afterNextRender?

Because that callback runs in the browser only, once, after the form is in the DOM. The constructor also runs on the server. When the request was made from the constructor, the server ran it as well and its HTML carried the text `Failed to parse URL from /api/ceremony`.

### Why is the checkbox disabled when the page arrives?

Because the form arrives as HTML before the script does, and hydration keeps the same checkbox element. In a test with the script held back, a box ticked that early stayed ticked and the SDK reported a `CR-01` finding at Block level. The box opens once the SDK observes it.

### Is the signup page rendered for each request?

No, not with the defaults. The server routes file that `ng new` writes sets every path to prerendering, and `ng build` reported one prerendered static route and wrote the form to `dist/my-app/browser/signup/index.html`. The session is created later, from the browser, so the static form is correct.

### Can a component read the key from process.env?

It compiles, and it must not. In a test, a component that read another variable from `process.env` passed `ng build`, the prerendered HTML file held the value from the build machine, and the browser logged `ReferenceError: process is not defined`. Read variables in `src/api.ts` only.

### Does the Angular quickstart need a domain or a card?

No. Test mode works on `localhost` with a test key, no card and no domain. You register and verify a domain only when you go live, and the Free plan then records 10 live signatures a month.

## Next steps

- [E-signatures and clickwrap for Angular](https://esigncomply.com/angular): what the integration gives you on this stack, with the things to watch for.
- [Browser SDK](https://esigncomply.com/docs/sdk/browser.md): every method the component calls, and what each one records.
- [Server confirmation](https://esigncomply.com/docs/guides/server-confirmation.md): the checks in step 6 and the `record.completed` webhook.
- [Node SDK](https://esigncomply.com/docs/sdk/node.md): every method the routes call, the endpoint behind it, and the errors.
- [All quickstarts](https://esigncomply.com/docs/quickstart.md#quickstarts-by-stack-and-platform).
