Skip to main content
import { useStytchB2BClient } from '@stytch/nextjs/b2b';

export const SessionDisplay = () => {
  const stytch = useStytchB2BClient();

  // Get cached session data synchronously
  const session = stytch.session.getSync();

  return (
    <div>
      {session ? (
        <p>Session ID: {session.member_session_id}</p>
      ) : (
        <p>No active session</p>
      )}
    </div>
  );
};
The Stytch SDK caches the Session of the logged-in . sessions.getSync is a synchronous method that fetches the cached session object. If there is no cached data, this method will return null.

Response

member_session_id
string
Globally unique UUID that identifies the Session.
member_id
string
Globally unique UUID that identifies a specific Member.
authentication_factors
array[objects]
An array of authentication factors that comprise a Session.
organization_id
The globally unique UUID that identifies the Organization associated with the Session.
organization_slug
The unique URL slug of the Organization associated with the Session.
roles
array[string]
A list of the roles associated with the Session. Members may inherit certain roles depending on the factors in their Session. For example, some roles may only be active if the member logged in from a specific SAML IDP.
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.
custom_claims
map<string, any>
The custom claims map for a Session. Claims can be added to a Session during a Sessions authenticate call.