Skip to main content

Testing tokens

In the console​

Widget & SDK → Test a token. Paste a token your server produced. Sarthi checks it exactly as a chat would and shows what it found: the claims it read, or the first thing wrong with it.

Testing doesn't use the token up, so you can test the same one and then start a chat with it.

What a result looks like when all is well:

Valid. user_id 4821, name "Ravi Mehta", email ravi@mehta.in, plan gold, expires in 14 minutes.

And when it isn't:

MessageFix
expiredThe token is older than its exp, or exp is more than 15 minutes after iat. Check your server's clock.
not yet validiat is in the future: the server's clock is ahead.
bad signatureWrong secret, or the wrong algorithm (it must be HS256).
user_id missingThe claim is required.
nonce missing or invalid16–64 characters of letters, digits, - and _.
already usedThat nonce started a chat before. Every token is single-use.
attrs too many / too longAt most 10 values, text up to 100 characters.

On the page​

Open your site in a private window (so no earlier chat is stored), log in, open the bubble. You should be greeted by name, with no form.

To see the token the page fetched, open the browser's developer tools → Network, and look for your token route. The response should be a fresh token on every call.

What the visitor sees when something is wrong​

The widget never shows technical detail to a visitor. These are the messages, and what they mean for you:

The visitor seesWhat happened
"We couldn't confirm your login. Please refresh the page and try again."The token was refused (expired, bad signature, used before). Fix the server; the visitor can chat anonymously after a refresh if your page falls back to that.
"Please refresh the page to start a new chat."The page gave one endUserToken, it was used, and there is no getEndUserToken to ask for another. Switch to getEndUserToken.

Both are logged nowhere visible to the visitor, but Test a token will reproduce the reason.

Checking the whole flow once​

  1. Log in as a test customer on your site.
  2. Ask the chat something only that customer's data could answer (if you connected a database), or just check that the greeting uses their name.
  3. In the console, open Conversations: the chat shows the signed-in id, the name and the plan from your token.
  4. Log out, open the chat: it must be a fresh, anonymous chat. The earlier chat must not reappear.