Without this step every browser is an anonymous visitor. With it, your server vouches for the user and Reponly shows the same conversation wherever they sign in. Agents also see the name, email and plan you send.
How it works
- Copy the secret key from the product's Identify users tab into your server's environment as
REPONLY_SECRET_KEY. Never send it to the browser. - Your server calls
POST /api/v1/identifywith the user and gets a short-lived identity token (15 minutes). - Your page passes that token to
window.Reponly.identify(token). - On sign-out, call
window.Reponly.logout()so the next person on that browser starts fresh.
On your server
// On your server, never in the browser.
const response = await fetch("https://reponly.com/api/v1/identify", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.REPONLY_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
projectKey: "pk_your_project_key",
user: { id: user.id, email: user.email, name: user.name, plan: user.planName, paying: user.isPaying },
organization: { id: user.teamId, name: user.teamName }, // optional
}),
});
const { data } = await response.json(); // { identityToken, expiresAt, expiresIn: 900 }In the browser
// In the page, after your backend returns the token:
window.Reponly.identify(identityToken);
// On sign-out, so the next person on this browser starts fresh:
window.Reponly.logout();Instructions for a coding agent
Paste this into Claude Code, Cursor or another coding agent, with your own project key in place of the example one:
Connect our signed-in users to Reponly live chat, so each user keeps the same chat on every browser and device.
Requirements:
1) The Reponly secret key is backend-only. Read it from the environment variable `REPONLY_SECRET_KEY`. Never send it to the browser.
2) Our project key is `pk_your_project_key` (public, safe in front-end code).
3) Add a backend route `POST /api/reponly-identity` for signed-in users only. It calls `POST https://reponly.com/api/v1/identify` with `Authorization: Bearer ${process.env.REPONLY_SECRET_KEY}` and returns `{ identityToken }` to our front end.
4) Reponly refuses /api/v1/identify calls that carry an Origin header (browsers), so this must be a server-to-server call.
5) Use our stable internal user id for `user.id`. Never use the email as the id: emails change.
6) The identity token lives 15 minutes. Fetch a fresh one on each page load or app start; don't store it.
7) In the front end, once the user is signed in, call our route and then `window.Reponly.identify(identityToken)`. The Reponly widget script must already be on the page.
8) On sign-out, call `window.Reponly.logout()`.
9) Handle errors: 400 (invalid payload; the response says which field), 401 (wrong project key or secret key), 429 (rate limited; the `Retry-After` header says when to retry). If identify fails, the chat still works anonymously, so log the error and carry on.
10) Add tests for the backend route: signed-in users get a token, signed-out users get 401, and Reponly errors are handled.
Request body (POST /api/v1/identify), exact field names:
type IdentifyPayload = {
projectKey: string; // "pk_your_project_key"
user: {
id: string; // required, max 200 chars
email?: string;
name?: string; // max 120 chars
image?: string; // https URL of their avatar
plan?: string; // plan name shown to support agents, max 60 chars
paying?: boolean; // paying customers get the project's paying rate limits
};
organization?: {
id?: string; // their team/company id; the same id across our products links bans
name?: string;
};
};
Response: { success: true, data: { identityToken: string; expiresAt: string; expiresIn: 900; customerId: string }, error: null }
Errors: { success: false, data: null, error: { code: string; message: string; retryAt: string | null } }