Sessions

A session creates a connection to TalkJS servers. A session represents a connection between:

  • a TalkJS app, as identified by your TalkJS app ID
  • a user, as identified by their user ID
  • that user's browser or the device they're currently using

Each user must have an active session to be able to use the chat.

Session lifecycle

Once created, a session exists for as long as the current browser context or application environment remains active. For example, until the user navigates away from the page or closes the tab.

The exact session lifecycle depends on how you're installing TalkJS.

Using the JavaScript Data API

If you're using the JavaScript Data API, whether on its own or together with React or Web Components, you can create a session using a TalkSession object. Multiple objects created with the same app ID and user ID combination share the same session.

The TalkSession automatically disconnects and reconnects as needed.

Using the Classic JavaScript SDK

If you're integrating TalkJS using the Classic JavaScript SDK, creating a session is typically the first thing you'll do.

A session ends automatically when the page reloads or the tab is closed.

If your app allows the user to log out without reloading the page, call the session's destroy method to destroy the session to clean up the old session.

Session security

TalkJS uses authentication (identity verification) to ensure that:

  • The user is who they say they are
  • The user has a valid login session on your app

This way, a TalkJS Session can only exist when the user is logged into your app, and not otherwise. We strongly recommend that you enable authentication so that accounts can't be hijacked.

Read all about authentication (identity verification). |

Further reading