Skip to main content
Anyone can open the browser console on your website and tell the chat widget they are someone else. Identity verification closes that gap: your server signs a short-lived token for the logged-in customer, the widget passes it along, and botBrains marks the user ID, email and phone from that token as verified. Audiences can then require verified fields, so a procedure that changes an order or reads account data only runs for verified customers.

How it works

  1. You create an identity secret for your project in the platform. Only your server knows it.
  2. When a customer is logged in, your server signs a token (a JSON Web Token) with that secret.
  3. Your page hands the token to the widget. botBrains checks the signature and the expiry, then identifies the customer from it.

Create the identity secret

Open Identity verification in your project settings and click Generate secret. The platform shows the secret once, together with its Key ID (kid), so store both in your server’s secret store right away. Generating, rotating and deleting the secret needs the permission to manage API keys.
Keep the identity secret on your server. Anyone who has it can sign in to the widget as any of your customers. Never put it in your website’s code or send it to the browser.

Sign a token on your server

Sign the token with HS256, put the key ID in the token header as kid, and keep its lifetime short: a few minutes is enough.
The Node.js example uses jsonwebtoken, the Python example PyJWT. Replace PROJECT_ID with your project’s ID, the number in your platform URL. If your user IDs are shorter than 16 characters, derive a longer one that stays stable, for example customer-000000042 for the user with ID 42. Never change it afterwards: botBrains recognizes the customer by it across visits and devices. Each claim in the token replaces the matching value you set in the browser, and the user ID always comes from sub. Fields the token doesn’t carry keep the value you set in the browser and stay unverified, just like custom attributes you pass with user.data.

Pass the token to the widget

Send the token from your server to the page and pass it to the Web SDK with user.data:
The widget takes this command right away, so its very first request already carries the token. botBrains identifies the customer by the token’s sub. Other fields you set, such as external_attributes, stay unverified. user.identify also accepts userJwt, but it only runs once the widget has loaded, so the widget’s first request goes out without the token. Tokens expire after a few minutes, and the widget doesn’t fetch new ones itself. Replace the token before it expires, for example on a timer slightly shorter than the token’s lifetime. In this example, /api/botbrains-token stands for your own endpoint that signs a new token for the logged-in customer:
If your page already receives a fresh session token on its own, pass a new userJwt at the same moment instead. When a different customer logs in on the same page, call user.logout before you pass their token. This clears the previous customer’s chat and data from the widget:
The widget keeps the token in memory only, never in cookies or local storage, and sends it with every request. user.logout and reset forget it. On frames that ask visitors to sign in, botBrains identifies the customer from that sign-in and ignores the token.

Use verified fields

Each identified user records which fields botBrains verified. Use them in an audience to limit sensitive procedures to verified customers:
A verified user ID proves who the customer is, not that the order or account they ask about is theirs. When an action reads or changes a customer’s data, look it up through the verified user ID or email, or check in your system that the requested order belongs to that customer. Otherwise a verified customer can ask about someone else’s order number.

Troubleshooting

When a token is invalid, botBrains returns an error and the widget doesn’t identify the customer.

Next steps

Identify users

Decide how to identify customers and what your AI agent can do for them

Audiences

Limit procedures to verified customers