Tori
  • Documentation
  • Pricing
Sign InSign Up
  • Getting started
  • Tori JavaScript guides
    • Add Tori to your site
    • Logged-in users
    • Google Tag Manager
    • Control the popup
    • Control conversations
    • Sizing and styling
  • Understanding Tori
    • Knowledge and research
    • Instructions and customisation
    • Conversations and context
    • Working with humans
  • Tori JavaScript reference
    • <tori-popup>
    • <tori-chatbox>
  • Default behaviour
    • Replies and language
    • Clarifying questions
    • Research and answers
    • Escalation
    • Staff messages and instructions
    • Off-topic questions and misuse

Logged-in users

If your user is logged in to your site and you want them to always have access to their Tori chats wherever they are logged in, pass a stable user ID and token to the element.

<tori-popup
  app-id="APP_ID"
  agent-id="AGENT_ID"
  user-id="user-123"
  token="USER_JWT"
></tori-popup>

Use the same attributes on <tori-chatbox> if you embed the inline chatbox.

Requirements

  • user-id must start with user-.
  • Provide token, tokenFetcher, or both when user-id is present.
  • Do not provide token without user-id.
  • tokenFetcher gets the initial token when token is omitted and refreshes short-lived tokens before they expire.

Generate the JWT on your server. Do not put your TalkJS secret key in browser code.

For refreshable tokens, expose an endpoint that authenticates the current user and returns a new JWT for the same user ID. Then assign it to the element:

const popup = document.querySelector("tori-popup");

popup.tokenFetcher = async () => {
  const response = await fetch("https://YOUR_BACKEND/api/tori-token", { method: "POST" });
  if (!response.ok) throw new Error("Could not refresh Tori token");
  const { token } = await response.json();
  return token;
};

You can find your secret key in the Tori dashboard.

See the TalkJS authentication docs for how to generate the token.

Typical flow

  1. Your user signs in to your site.
  2. Your backend creates a user token for that user.
  3. Your page renders <tori-popup> with user-id and either sets token, assigns tokenFetcher, or does both.
  4. Tori uses that identity when loading the user's conversations.

Anonymous visitors

For public pages where visitors are not logged in, omit user-id and token. Tori will create and remember an anonymous visitor identity in the browser.

Tori

Here you can add a description about your company or product

© Copyright 2026 AskTori. All Rights Reserved.

About
  • Contact
Product
  • Documentation
Legal
  • Terms of Service
  • Privacy Policy
  • Cookie Policy