# Sign in your visitors (identity verification)

> Let your agent recognise signed-in customers securely, so nobody can pretend to be someone else.

Source: https://help.askmavis.co/help/identity-verification  
Collection: Install your agent  
Last updated: 2026-12-05

If your website has customer accounts, identity verification lets the messenger know who each signed-in customer is. Your server signs a token with a secret only you know, so nobody can pretend to be another customer. Your team sees each signed-in customer as one contact with their name and email, whichever device they use, and your agent can run actions that need a verified customer. Each device keeps its own chat history: a chat started on one device isn't shown on another yet.

## Before you start

You need a developer who can change your website's server code.

## 1. Create a secret

1. Open your agent and go to **Install**.
2. Open **Advanced** at the bottom of the page. Under **Identity verification**, click **Create secret**.
3. Copy it into your server's environment now, for example as `ASKMAVIS_IDENTITY_SECRET`. It won't be shown again. Never put it in browser code.

**Rotate secret** creates a new one. Tokens signed with the old secret stop working, so every visitor is signed out until your server uses the new one.

## 2. Sign a token on your server

After a customer signs in, sign an HS256 JWT with the secret. Include:

- `user_id` (or `sub`): required, your customer's stable ID
- `email` and `name`: recommended
- `exp`: required, an expiry a few hours ahead at most. Tokens without `exp` are refused.

```js
// Node.js, using the jsonwebtoken package
const token = jwt.sign(
  {
    user_id: user.id,
    email: user.email,
    name: user.name,
    exp: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour
  },
  process.env.ASKMAVIS_IDENTITY_SECRET,
  { algorithm: 'HS256' },
);
```

## 3. Pass the token to the messenger

On the page, after the install code:

```js
window.AskMavisMessenger.push({ command: 'identify', token });
```

When the customer signs out:

```js
window.AskMavisMessenger.push({ command: 'resetUser' });
```

## 4. Choose how strict to be

Under **Verification**, pick:

- **Off:** everyone chats as an anonymous visitor. Tokens are ignored.
- **Verify when sent:** signed-in customers are recognised from their token. Visitors without a valid token chat anonymously.
- **Require sign-in:** only visitors with a valid token can chat. Use this when the widget lives inside your logged-in app.

## Test it

In the **Playground**, use **Chat as user** to see how your agent answers a signed-in customer.

## Related

- [Custom actions](https://help.askmavis.co/help/custom-actions)
- [Add the messenger to your website](https://help.askmavis.co/help/add-the-messenger-to-your-website)
