Skip to content
Widget SDK

User Sessions

Manage login, logout, and user switching with session lifecycle best practices.

On this page

User Sessions#

The Widget SDK handles guests, visitors you know by name, and visitors signed in to your site. This page covers the session lifecycle — from sign-in to sign-out and switching between users on one browser.

How Sessions Work#

Gydr gives every browser a visitor id (vis_…), kept inside the chatbox’s own storage. A visitor returning in the same browser sees their conversation; clearing storage starts a new visitor. You never choose a visitor id — no page, link or API call can — and a signed-in visitor’s id (usr_…) is made by Gydr from the check of their token (see Guests & data never to send).

Visitor
Guest
How you tell Gydr
Nothing to do
Personal lookups
No
Greeted by name
No
Visitor
Known but unverified
How you tell Gydr
Gydr.setVisitorDetails({ name, email }) or data-visitor-* attributes
Personal lookups
No
Greeted by name
Yes
Visitor
Signed in
How you tell Gydr
The visitor's token: the Gydr WordPress plugin, your identity provider, or your own server
Personal lookups
Yes — e.g. their own orders
Greeted by name
Yes

Sign-in — Identifying a User#

A signed-in visitor is recognised from the visitor’s token: the Gydr WordPress plugin serves it, or your identity provider or server does, and the widget fetches it from an endpoint on your site (shown below). Gydr checks it on its own servers through the widget’s sign-in source and decides the sign-in state — the page never does. There is nothing to call when someone signs in — the widget asks your endpoint before the first message and whenever the token is about to expire. The full guide, with server code, is Signed-in visitors.

<!-- The same tag for guests and signed-in visitors -->
<script
  src="https://cdn.infinichat.dev/widget.js"
  data-api-key="pk_live_YOUR_KEY"
  data-visitor-token-endpoint="/gydr/visitor-token"
  async
></script>
Never sign tokens in browser JavaScript and never send a signing key to the page — either one lets anyone pose as any of your users.

Sign-out — Automatic#

With data-visitor-token-endpoint or Gydr.setVisitorTokenProvider(), sign-out needs no code. When your endpoint returns { "visitorToken": null }, the widget starts a new visitor with an empty conversation. The same happens when a guest signs in, and when a different person signs in on the same browser (a different User ID): the previous conversation is cleared, and it can never continue for anyone else — not even after a page reload. A signed-in person’s past chats are shown only while they are signed in, and signing back in brings them back. In a single-page app, call Gydr.refreshVisitorToken() right after your own sign-in or sign-out so the switch happens at once.

Clearing everything — Gydr.reset()#

reset() clears all visitor data and rebuilds the widget in place as a fresh guest — even a reload straight after starts fresh. Use it when you want a complete wipe on a shared device.

function handleLogout() {
  Gydr.reset();          // 1. clear the chatbot (it rebuilds as a fresh guest)
  auth.signOut();        // 2. your own sign-out
}

Switching Users (User A → User B)#

Switching is automatic: once your site returns User B’s token, Gydr sees a different User ID and the widget becomes a new visitor with a new conversation. In a single-page app, ask for the new token at once:

// User A signs out, User B signs in (your own code)
await auth.switchUser('b');

// The provider now answers with User B's token
Gydr.refreshVisitorToken();

What reset() Clears#

Action
Visitor ID
Details
Removed from storage inside the chatbox iframe origin (not accessible to the host page)
Action
Chat session
Details
Removed from storage inside the chatbox iframe origin (not accessible to the host page)
Action
Visitor token
Details
Dropped from memory
Action
Visitor details and cart
Details
Dropped from memory
Action
Widget
Details
Rebuilt in place as a fresh guest — the launcher stays, the panel closes; a chatbox() / bubble() call right after replaces it
Action
Next page load
Details
Starts fresh too — a one-time marker (a timestamp only, nothing about the visitor) on your site makes the next widget forget the visitor
Action
Token source
Details
Stays registered — the fresh widget asks it again

Ready to get started?

Create a free account and deploy your first chatbot in minutes.