Browse documentation
Identify logged-in visitors
Tell the chat widget who your logged-in user is, signed with HMAC-SHA256 so it can be trusted. Works with any backend.
Optional. The widget works without it. This is for products where your visitors are already signed in and you would rather the conversation arrived with a name on it.
Signed, or it doesn't count
Anything a browser can assert, a visitor can edit. So there are two levels of trust, and the difference is the whole design.
With a valid signature
- The conversation is labelled with their name.
- They become a contact the moment they say hello.
- Their email is safe for us to reply to.
- The agent knows who it is talking to and stops asking.
- You can see every conversation they have ever had.
Without one
- We show the name, and treat it as decoration.
- We will not store the email address or send anything to it.
- No contact is created from the claim.
We email visitors when you reply after they have left the page. An unverified address would let anyone on your site have us mail someone who never asked to hear from us.
1. Sign the visitor on your server
Hash the user's id and their email, separated by a newline, with HMAC-SHA256 and your signing secret. Never do this in the browser, where the secret would be readable by anyone who views source.
The string to sign is exactly userId + "\n" + email, with an empty string where a user has no email. Both fields, not just the id. Otherwise a signature stays valid while the email underneath it is swapped, and the email is the part we can deliver to.
import { createHmac } from "node:crypto";
const userHash = createHmac("sha256", process.env.WHIZ_IDENTITY_SECRET)
.update(`${user.id}\n${user.email ?? ""}`)
.digest("hex");require "openssl"
user_hash = OpenSSL::HMAC.hexdigest(
"SHA256",
ENV.fetch("WHIZ_IDENTITY_SECRET"),
"#{user.id}\n#{user.email}"
)import hashlib, hmac, os
user_hash = hmac.new(
os.environ["WHIZ_IDENTITY_SECRET"].encode(),
f"{user.id}\n{user.email or ''}".encode(),
hashlib.sha256,
).hexdigest()<?php
// Note the argument order: data first, then the key.
$userHash = hash_hmac(
'sha256',
$user->id . "\n" . ($user->email ?? ''),
getenv('WHIZ_IDENTITY_SECRET')
);Your signing secret is in the dashboard under Settings → Installation. Store it the way you would a database password.
2. Pass it to the widget
Render this wherever you already render the embed snippet. The stub means you can call it before the widget has finished loading.
<script>
window.whizChat = window.whizChat || function () {
(window.whizChat.q = window.whizChat.q || []).push(arguments);
};
window.whizChat("identify", {
userId: "usr_1234", // your own id for this person
name: "Jo Kelly", // optional
email: "jo@acme.com", // optional
userHash: "a3f1..." // from step 1
});
</script>Call it on every page, not just after login
We check the signature on every message, so identity travels with the conversation rather than being remembered from an earlier request. Someone who browses anonymously and then signs in keeps the thread they already started.
Clear it on logout
Call whizChat("shutdown") so the next person on a shared computer starts a fresh conversation instead of seeing the last one's. If a different signed-in user turns up on the same browser anyway, we start a new conversation for them rather than continuing someone else's.
A wrong hash won't break anything
If the signature doesn't match we fall back to treating the visitor as unverified. They keep their conversation; you lose the name. Nothing errors, which is worth knowing because it also means a broken integration is quiet, so check a live conversation to be sure.
How to tell it worked
Open the conversation in your dashboard. Under the visitor's name it will say Verified by your site, with their email beside it. If it says Name unverified, the hash didn't match. Usually that is the wrong secret, or signing the id without the email.
Rotating the secret
Rotating takes effect immediately, so every hash your servers are computing with the old value stops matching until you deploy the new one. Visitors show as unverified in the meantime. Nothing breaks, but nothing tells you either.
3. Let the agent look up their account
Procedures can read a signed-in customer's own records, such as their plan and invoices in Stripe. For that the hash is not enough: we also need a short-lived token, so a copied signature can't be replayed forever or on someone else's site.
import { WhizIdentity } from "@whiz.chat/node";
// Your site id is on Settings → Installation.
const whiz = new WhizIdentity(process.env.WHIZ_IDENTITY_SECRET!, { siteId: "YOUR_SITE_ID" });
// Returns userHash and identityToken. Pass the whole object to identify.
const identity = whiz.sign({ userId: user.id, name: user.name, email: user.email });Header: { "alg": "HS256", "typ": "JWT" }
Payload: {
"sub": "usr_1234", // the same userId you send
"email": "jo@acme.com", // the same email you send, or null
"aud": "YOUR_SITE_ID",
"iat": 1793750400, // now, in seconds
"exp": 1793754000 // up to 24 hours later
}
Signed with HMAC-SHA256 and the same signing secret.Then add it to the same call: identityToken: "eyJ...".
Only needed for account lookups
Without a token everything above still works: the name, the contact, the history. A procedure that reads a customer's own records will tell them it can only do that when they're signed in, and pass the conversation to your team.
Keep it short-lived
We refuse tokens that live longer than 24 hours, and the Node package defaults to one hour. Mint a fresh one with each page you render. If someone keeps a tab open past its expiry, the conversation carries on; only account lookups pause until the next page load.
It names your site
The token only works for the site id inside it, and the user id and email you send beside it must match it. A token that disagrees with them verifies nothing.