Skip to main content
'use client';

import { useStytchMemberSession } from '@stytch/nextjs/b2b';

export const SessionInfo = () => {
  const { session, isInitialized } = useStytchMemberSession();

  if (!isInitialized) {
    return <p>Loading...</p>;
  }

  return session ? (
    <div>
      <p>Session ID: {session.member_session_id}</p>
      <p>Expires: {new Date(session.expires_at).toLocaleString()}</p>
    </div>
  ) : (
    <p>No active session</p>
  );
};
To get the active session of the currently signed in , use the useStytchMemberSession hook. If the user is not signed in, the returned value will be null. In non-React environments, use the session.getSync method to get the Session.

Return Value

session
object | null
The current Session.
fromCache
boolean
Whether the Member data is from persistent storage.