Skip to main content
import { StytchClient } from '@stytch/vanilla-js';

const stytch = new StytchClient('${publicToken}');
const session = stytch.session.getSync();

if (session) {
  console.log('Session ID:', session.session_id);
}
The Stytch SDK caches the Session of the logged-in . session.getSync is a synchronous method that fetches the cached Session object. If there is no cached data, this method returns null. The session.getInfo method is similar to session.getSync, but returns an object containing the session object and a fromCache boolean. If fromCache is true, the session object is from the cache and a state refresh is in progress. You can listen for changes with the session.onChange method, which invokes your callback whenever the Session object changes.

Response

session_id
string
A unique identifier for a specific Session.
user_id
string
The unique ID of the affected User.
authentication_factors
array[objects]
An array of different authentication factors that comprise a Session.
started_at
string
The timestamp when the Session was created. Values conform to the RFC 3339 standard and are expressed in UTC, e.g. 2021-12-29T12:33:09Z.
last_accessed_at
string
The timestamp when the Session was last accessed. Values conform to the RFC 3339 standard and are expressed in UTC, e.g. 2021-12-29T12:33:09Z.
expires_at
string
The timestamp when the Session expires. Values conform to the RFC 3339 standard and are expressed in UTC, e.g. 2021-12-29T12:33:09Z.
attributes
object
Provided attributes help with fraud detection.
custom_claims
map
The custom claims map for a Session. Claims can be added to a session during a Sessions authenticate call.
roles
array[string]
A list of the roles associated with the session.