Skip to main content

Sign the JWT

The contract is the same everywhere: read your user’s session, then sign a new JWT (HS256) with your signing key and the visitor’s email. Start with your language, then check your auth provider for how to read the user.
Always sign server-side. The signing key never belongs in frontend code or a public repository.

Let Your AI Add It

Most teams wire this up with an AI coding assistant. Copy the prompt below into yours (Cursor, Claude Code, Copilot, and similar). It inspects your stack first, asks if anything is unclear, then writes the signing code for you.
Prompt for your AI assistant
The signing key is created in your widget settings (Security / Identity Verification). Paste it as the BESTCHATBOT_SIGNING_KEY secret when your assistant asks.
Prefer to do it by hand? The exact code per language and provider follows.

Any Backend

Required: email (lowercase) and exp. Recommended: name. The signing key comes from a backend secret (BESTCHATBOT_SIGNING_KEY).
Then hand token to the widget with setUserToken(token) or the data-user-token attribute. See Visitor Identity.

By Auth Provider

Each provider differs only in how you read the signed-in user. Once you have the email, sign the token with one of the snippets above.
Easiest path: install the BestChatBot plugin, paste your signing key in its settings, and it injects the widget and mints the token for you (including WooCommerce email and phone). No code needed.To do it by hand, sign in the footer for logged-in users:
Inline tokens can be cached by page caches. The plugin avoids this by fetching the token through a non-cached request. Prefer the plugin on cached sites.
Read the Clerk user server-side, then sign your own token.
Do not forward Clerk’s session token. Mint a new JWT signed with your BestChatBot signing key.
Verify the Firebase ID token first, then sign.
The frontend sends the Firebase ID token to your endpoint; your endpoint returns the BestChatBot JWT.
Read the user with getUser() (not getSession()), then sign.
Do not forward Supabase’s access token. Sign a separate JWT with your signing key.
Read the Auth0 session server-side, then sign.

Next Steps

Visitor Identity

The contract, security rules, and how to deliver the token.

Members & Roles

Control who on your team can manage the widget.