Identify logged-in users in your chat widget
Why a chat widget should trust only a token your server signs, how JWT identity verification works, and signing one in Node.js, Python, Ruby, PHP or Go.
The Notert teamMonday, November 30th, 202610 min read

On this page
Most chat widgets let you tell them who's signed in with one line of JavaScript: pass the user's id, email and name, and the conversation is theirs. It's quick, and it's also the part of a support widget most worth getting right, because a widget that believes whatever the browser tells it will believe an attacker too.
This guide explains how identity verification for a chat widget works, why a token your server signs is the safe way to identify logged-in users, and how to set it up end to end, with Notert's widget as the example. The ideas apply to any support tool you use.
Why you identify users at all
An anonymous visitor is known by their browser. Their conversations live in that browser, and your team sees whatever name and email they type. That's fine on a marketing site. Inside your product, it's a poor experience on both sides:
- The customer starts over on every device. A question asked on their laptop isn't there on their phone.
- Your team answers blind. They don't know which account wrote, what plan it's on, or whether the email typed is even the customer's.
- Replies go astray. A typo in a typed email address means the answer never reaches anyone.
Once your product tells the widget who's signed in, the same person finds the same conversations everywhere, and your team sees the name and email your product knows, marked as verified, beside every message.
The problem with identifying users from the browser
Here's the shape of an unverified identify call, as many widgets offer it:
// Don't trust this on its own.
widget.identify({ id: "1842", email: "priya@northwind.example", name: "Priya Shah" });Anything your page can call, anyone with the browser's console can call too. If the widget accepts that object as the truth, someone can type another customer's id or email and:
- Read their conversations, including whatever they or your team wrote in them: invoices, account details, private links.
- Write as them, asking your team to change an email address, refund an order or reset access, with your inbox showing the real customer's name.
This isn't a hypothetical risk that needs a clever exploit. It needs a browser and a guess at an email address. That's why serious support tools pair identify with a signature your server makes, often called identity verification or user verification.
How identity verification works
The fix is to make the browser a courier, not a witness. Your server, which already knows who's signed in, signs a statement saying so with a secret only it and the support tool hold. The page carries the signed statement to the widget, and the support tool checks the signature before it believes a word.
- Your user signs in to your product, as they do today.
- Your server signs a token naming them, with the identity secret only it holds.
- Your page passes the token to the widget.
- The support tool checks the signature against your secret, and the widget opens as that person.
Nothing about the person travels unsigned, and the secret never reaches the browser. A token can't be edited without breaking its signature, and one person's token can't be turned into another's.
HMAC hash or signed JWT?
There are two common ways to sign. The older one sends the user's id or email as usual, plus an HMAC hash of it made with your secret. The newer one, which Notert uses, sends a JSON Web Token: the claims and the signature in one string.
How to read the table:
- Yes The method does it.
- Partly It does it in a narrower form, with a word on how.
- No It doesn't.
| What you need | HMAC of an id or email | Signed JWT |
|---|---|---|
| Proves who the user is | Yes | Yes |
| Stops working after a set time | No | Yes |
| Signs the name, email and traits too | Partlyone value | Yes |
| Says whether the email was confirmed | No | Yes |
| Signed with standard libraries | Yes | Yes |
The expiry is the difference that matters most. An HMAC of a user id is valid forever: if it leaks into a log or a screenshot, it identifies that user until you rotate your secret. A JWT carries an exp, so a leaked token is soon worthless, and you can keep tokens short-lived without your users noticing, as the next sections show.
What the token says
Notert's token is a JWT signed with HS256 under your workspace's identity secret. It holds:
sub: your own id for the user. Two tokens with the samesubare the same person, on any device.email: the address they signed in to your product with.email_verified:trueonce your product has confirmed the address, such as by an emailed link. Notert treats whoever the token names as the owner of that address, so a token for an address no one proved is refused.name: optional, the name your team sees.iatandexp: when it was signed and when it stops working. Tokens are short-lived on purpose.
It can also carry what helps your team answer: the user's language, their picture, the companies they belong to, and traits of your own, such as plan or seats. Your team sees each of these beside the person's conversations, and they're signed like the rest, so nobody can raise their own plan from the console. See what the token says.
Step 1: copy your identity secret and keep it on the server
Open Settings, then MCP & API (opens Notert in a new tab), and find Identity secret under Secrets, or open the Signed-in users tab of the widget's install guide, where the same secret is the first step. Owners and admins can copy it.
Put it where your other server secrets live, in an environment variable named NOTERT_IDENTITY_SECRET:
# .env.local, listed in .gitignore
NOTERT_IDENTITY_SECRET=nis_...Never put it in your front-end code or your repository. In a framework that sends some variables to the browser, such as Next.js with its NEXT_PUBLIC_ prefix or Vite with VITE_, never give the secret such a name. Anyone holding it can sign a token for any of your users.
Step 2: sign a token on your server
In Node.js, with jose:
import { SignJWT } from "jose";
const token = await new SignJWT({
email: user.email,
...(user.name ? { name: user.name } : {}),
email_verified: true,
})
.setProtectedHeader({ alg: "HS256" })
.setSubject(String(user.id))
// Set the expiry before the issue time: each reads the clock, and the other order can sign a
// token a second longer than the widget accepts.
.setExpirationTime("1d")
.setIssuedAt()
.sign(new TextEncoder().encode(process.env.NOTERT_IDENTITY_SECRET));In Python, with PyJWT:
import os
import time
import jwt
now = int(time.time())
claims = {
"sub": str(user.id),
"email": user.email,
"email_verified": True,
"iat": now,
"exp": now + 86400,
}
if user.name:
claims["name"] = user.name
token = jwt.encode(claims, os.environ["NOTERT_IDENTITY_SECRET"], algorithm="HS256")In Ruby, with the jwt gem:
require "jwt"
now = Time.now.to_i
claims = { sub: user.id.to_s, email: user.email, email_verified: true, iat: now, exp: now + 86_400 }
claims[:name] = user.name if user.name
token = JWT.encode(claims, ENV.fetch("NOTERT_IDENTITY_SECRET"), "HS256")PHP and Go take the same few lines. All five, with every optional claim, are in sign a token on your server. Use the secret exactly as Notert shows it, starting nis_, as text, without decoding it first.
Step 3: get the token to your page
There are two ways, and both keep the secret on the server.
Write it into the page your server renders for a signed-in user, then hand it over in a script on that page:
window.notert.identify("TOKEN_YOUR_SERVER_SIGNED");Or serve it from your API, which suits a single-page app. A route behind your own sign-in, in Express:
app.get("/api/notert-token", requireSignedIn, async (req, res) => {
const token = await signWidgetToken(req.user); // the jose example above
res.set("Cache-Control", "no-store").json({ token });
});Cache-Control: no-store keeps a shared cache from handing one user's token to another, a mistake that's easy to make and hard to notice.
Step 4: keep it fresh, and sign out properly
A short-lived token raises a fair question: what happens to a tab left open overnight? Rather than a token, pass the widget a function that fetches one:
window.notert.identify(async () => {
const response = await fetch("/api/notert-token", { credentials: "same-origin" });
if (!response.ok) return null;
return (await response.json()).token;
});The widget asks it at once and waits for the answer before it reads anything, so it never shows the user as someone else first. It asks again a few minutes before each token expires, and once more if a call is refused for an expired token, as when a laptop wakes up the next morning. Your users never see any of it.
When someone signs out, tell the widget:
window.notert.identify(null);This matters more than it looks. Until you do, the widget keeps the person who signed in, so on a shared computer the next one would open their conversations. A token for a different user also starts the widget over, with nothing it read for the one before, and the token lives only in the page's memory, never in storage. In a single-page app, call identify from your sign-in and sign-out code, not a script rendered with the page, since that doesn't run again. See the React guide and the Next.js guide for working examples.
Step 5: check it works
On the install guide's Signed-in users tab, open Check a token, paste one your server signed and press Check. It says whom the widget would know it as and when it stops counting, or exactly what's wrong with it. Below that it lists each optional claim as Notert reads it, and any it ignored and why, such as a photo on a private address. An ignored claim never stops a token from working, so this is the one place that says so.
Then sign in to your live site and open a page with the widget. Check it works, at the end of the same tab, says when the widget last loaded for a signed-in visitor. It counts your websites, not localhost.
The mistakes we see most
| What you see | Usually because |
|---|---|
| The widget is hidden for signed-in users | The token was refused. The browser's console says why; paste it into Check a token |
| Users are signed out of the widget after a while | A token was passed rather than a function that fetches a fresh one |
| Your team sees the name the visitor typed, not yours | identify isn't called on that page, or is called before your app knows the user |
| Every token is refused | The secret was decoded, trimmed or swapped for an old one after a revoke |
| A token is refused for one user only | email_verified is missing or false for an address your product never confirmed |
A widget that can't verify a token hides itself for that user, and says why in the console, rather than treating them as someone else. That's deliberate: showing the wrong person's conversations is worse than showing none.
If your secret leaks
Revoke it. Under Secrets on MCP & API (opens Notert in a new tab), press Revoke secret, confirm, and put the new secret on your server. The old one stops at once, so until your server signs with the new one, signed-in users see no widget, and visitors who aren't signed in aren't affected. Each revoke is recorded in the audit log, and the workspace's owners are emailed. See your identity secret.
The same token signs people in on your board
Once your server signs tokens, it can also sign people in on your public feedback board, so a customer who clicks from your app to your roadmap is already signed in to vote and comment. A board token carries one more claim, an audience, and lasts only minutes. See sign in on your board.
Using an AI coding agent?
On the install guide's Signed-in users tab, press Copy prompt and paste it into Cursor, Claude Code or another agent. It carries the code above and tells the agent where each part goes. It names your identity secret only by its environment variable, so you still put the secret on your server yourself.
Questions people ask
Is passing the user's email to the widget enough?
Only if the widget checks a signature too. An email passed from the browser on its own can be changed by anyone with the console, so a widget that trusts it lets one customer read and write as another.
Should I sign tokens with HMAC or a JWT?
Both prove who the user is. A JWT also carries an expiry and signs every detail about the user, so a leaked token soon stops working and nobody can change their own traits. Notert uses a JWT signed with HS256.
Where should I generate the token?
On your server, in the code that already knows who's signed in: a route handler, a server-rendered page, or your API. Never in the browser, since signing there would mean shipping your secret to every visitor.
Does a short-lived token sign users out of the widget?
Not if you pass a function to identify. The widget asks it for a fresh token before each one expires and after a laptop wakes, so the user never notices.
Are conversations from before they signed in joined to their account?
No. Conversations someone started in a browser before signing in stay with that browser, since anyone could have used it.
Next.js, Vite, Express, Cursor and the other names here belong to their owners. Notert is independent of them and isn't endorsed by them.


