# Verify customer identity

Sign short-lived JWTs on your server so the messenger knows which customer is signed in and trusts their attributes.

With identity verification, your server signs a short-lived JWT for the logged-in user. The messenger sends that token to dimmi and signs the visitor in as the customer matching its `sub` claim.

## Create a signing secret

Open **Settings → Identity verification**, create a **Shared secret (HS256)**, and save both values in your server environment:

```bash title=".env"
DIMMI_IDENTITY_SECRET=dmi_idsec_<secret>
DIMMI_IDENTITY_KID=isk_<key_id>
```

Prefer asymmetric keys (RSA, P-256, or Ed25519)? Add your public key in dimmi and set `DIMMI_IDENTITY_PRIVATE_KEY` to your private key PEM on the server.

![The Secrets section of Settings → Identity verification, listing an HS256 secret named Production with Rotate and Revoke buttons.](https://trydimmi.com/docs/shots/identity-secrets-light.webp)

## Sign tokens on your server

`@dimmi/server` and `@dimmi/nextjs` read those environment variables automatically and sign tokens valid for 600 seconds by default (`expiresIn`, up to 3,600 seconds).

<Tabs>
<TabItem label="Next.js">

```bash
npm install @dimmi/nextjs
```

```ts title="dimmi.config.ts"

export default defineDimmi({ identify: clerk() });
```

```ts title="app/dimmi-token.ts"
"use server";

export async function dimmiToken() {
  return identityToken(config);
}
```

```tsx title="app/layout.tsx"

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Dimmi appId="<app_id>" host="https://trydimmi.com" identity={dimmiToken} />
      </body>
    </html>
  );
}
```

| Auth library | `identify` helper | Import |
| --- | --- | --- |
| Clerk | `clerk()` | `@dimmi/nextjs/clerk` |
| Auth.js | `authjs(auth)` | `@dimmi/nextjs/authjs` |
| Supabase | `supabase()` | `@dimmi/nextjs/supabase` |
| Better Auth | `betterAuth(auth)` | `@dimmi/nextjs/better-auth` |
| Custom auth | Function returning a user object or `null` | None |

</TabItem>
<TabItem label="Express">

```bash
npm install @dimmi/server
```

```js title="server.mjs"

const app = express();

// Your session middleware sets req.user.
app.get(
  "/api/dimmi/token",
  dimmiIdentity((req) =>
    req.user
      ? { id: req.user.id, email: req.user.email, emailVerified: req.user.emailVerified }
      : null,
  ),
);

app.listen(3000);
```

</TabItem>
</Tabs>

The user object accepts `id` (required), `email`, `emailVerified`, `name`, `phone`, `avatarUrl`, `locale`, `timezone`, `signedUpAt`, `company`, and `attributes`.

Our [Go](/developers/sdks/go/), [PHP](/developers/sdks/php/), [Laravel](/developers/sdks/laravel/), and [Python](/developers/sdks/python/) SDKs also include token helpers. If you use a generic JWT library, pass the full `dmi_idsec_` string as the HMAC key without base64-decoding it, and include the key ID in the `kid` header.

## Pass the token to the messenger

In Next.js, pass your server action to the `identity` prop. In other frameworks, choose one of two options:

- **`identityUrl`** (`data-identity-url` on the script tag): a same-origin endpoint (like `/api/dimmi/token`) returning `200` with `{"token": "<jwt>"}`, or `{"token": null}` when signed out.
- **`identity`**: a function that returns the JWT string or `null`.

The messenger fetches a token on page load. In single-page apps, call `identify()` after login and `shutdown()` after logout (`refreshDimmiIdentity()` and `dimmiLogout()` in `@dimmi/nextjs`).

## Supported JWT claims

`sub` and `exp` are required. Invalid optional claims are dropped.

| Claim | Rule |
| --- | --- |
| `sub` | Your user ID (1 to 255 characters). |
| `exp` | Expiration Unix timestamp, at most 7 days after `iat`. Allows 60 seconds of clock skew. |
| `aud` | `dimmi`, the messenger's app ID, or the workspace ID. Omit to accept any messenger. |
| `nonce` | Up to 128 characters. Tokens with a `nonce` can only be used once. |
| `email` | Up to 254 characters. |
| `email_verified` | Set `true` to mark the email verified and link past email conversations. |
| `name` | 1 to 120 characters. |
| `phone` | E.164 format, such as `+14155550100`. |
| `avatar_url` | `https` URL, up to 2,048 characters. |
| `locale`, `timezone` | Language tag (like `en-US`) and IANA time zone (like `Europe/Paris`). |
| `company` | Object with `id` (required), `name`, `domain`, and `custom_attributes`. |
| `custom_attributes` | Up to 100 keys (lowercase letters, digits, underscores, starting with a letter). Values can be numbers, booleans, strings up to 1,024 characters, or `null` to clear. |

Only verified token attributes (or API/import attributes) can be bound into [dimmi agent actions](/ai/actions/).

## Reuse your auth provider's tokens (JWKS)

To skip signing your own tokens, create an **Auth provider key set (JWKS)** secret with your provider's JWKS URL, then pass your provider's session JWT via `identity`. Leaving **Issuer** blank defaults to the JWKS URL without `/.well-known/`.

## Rotate or revoke secrets

- **Rotate:** generates a new secret while keeping the old one valid for 7 days.
- **Revoke:** invalidates the secret right away, signs out every session created with it, and cannot be undone.

## Limits

| Limit | Value |
| --- | --- |
| Max token size | 8 KB |
| Messenger session lifetime after last verified token | 24 hours |
| Secrets per workspace | 5 |

## Debug tokens or require sign-in

Paste any JWT into **Check a token** under **Settings → Identity verification** to inspect its claims and see why a token was rejected. On the same page, switch sign-in mode to **Required** to hide the messenger from signed-out visitors.

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
