---
title: Customer identity
description: Verify customer accounts and keep their conversation history.
icon: User
---

Use identity mode for signed-in customers. Your server verifies the account and signs an identity token.
All widgets can use the same identity route and API key pair.

## Before you start

Create a key pair in **Settings > API keys**.
Store its server key in a server environment variable:

```bash title=".env.local"
CORISTEN_KEY=coristen_key_...
```

Do not expose this key in browser code.

## Add the identity route

Connect the route to your application authentication system.
In this example, replace `getSignedInUser` with your own authentication function.

```ts title="app/api/coristen/identity/route.ts"
import { coristenIdentity } from "@coristen/widget/server"
import { getSignedInUser } from "@/lib/auth"

export const { GET } = coristenIdentity(async (request) => {
  const user = await getSignedInUser(request)
  return user ? { id: user.id, name: user.name, email: user.email } : null
})
```

Use a stable account ID. Do not use an email address as the account ID if the address can change.
The route must verify the current session. Do not accept an account ID supplied by the browser.

## Connect the widgets

```tsx
<>
  <CoristenWidget identity="/api/coristen/identity" />
  <CoristenContactForm identity="/api/coristen/identity" />
</>
```

Use this same route for `CoristenDock` and `CoristenModal`.
Do not supply an `apiKey` prop when you use `identity`.
The route supplies the public key from the server key pair.

## Check access

1. Sign in to your application.
2. Open chat.
3. Send a message.
4. Open the application in another browser.
5. Sign in with the same account.
6. Open chat and check the conversation history.

Identity mode rejects requests without a verified customer account.
After sign-out, call `coristenWidget.reset()` to replace the widget session.
