> ## Documentation Index
> Fetch the complete documentation index at: https://stytch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# useStytchSession

> Access the current session state using the Stytch Next.js SDK

export const isReactNative_0 = undefined

To get the active Session for the currently signed in User, use the `useStytchSession` hook.

If no User is signed in, the returned value will be `null`.

{!isReactNative_0 && <>If this hook may be rendered in a server environment, use the <code>isInitialized</code> property to determine if the SDK has completed initialization before using Session data.</>}

In non-React environments, use the [`session.getSync`](/api-reference/consumer/frontend-sdks/vanilla-js/methods/sessions/get-session-sync) method to get the Session.

## Return Value

<ResponseField name="session" type="object | null">
  The current Session.

  <Expandable title="properties">
    <ResponseField name="session_id" type="string">
      A unique identifier for a specific Session.
    </ResponseField>

    <ResponseField name="user_id" type="string">
      The unique ID of the affected User.
    </ResponseField>

    <ResponseField name="authentication_factors" type="array[objects]">
      An array of different authentication factors that comprise a Session.
    </ResponseField>

    <ResponseField name="started_at" type="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.
    </ResponseField>

    <ResponseField name="last_accessed_at" type="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.
    </ResponseField>

    <ResponseField name="expires_at" type="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.
    </ResponseField>

    <ResponseField name="attributes" type="object">
      Provided attributes help with fraud detection.

      <Expandable title="properties">
        <ResponseField name="ip_address" type="string">
          The IP address of the user.
        </ResponseField>

        <ResponseField name="user_agent" type="string">
          The user agent of the User.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="custom_claims" type="map">
      The custom claims map for a Session. Claims can be added to a session during a Sessions authenticate call.
    </ResponseField>

    <ResponseField name="roles" type="array[string]">
      A list of the roles associated with the session.
    </ResponseField>
  </Expandable>
</ResponseField>

{!isReactNative_0 && (
<ResponseField name="isInitialized" type="boolean">
  Whether the SDK has completed initialization.
</ResponseField>
)}

<ResponseField name="fromCache" type="boolean">
  Whether the Session data is from persistent storage.
</ResponseField>

<Panel>
  <RequestExample>
    ```jsx Next.js theme={null}
    import { useStytchSession } from '@stytch/nextjs';

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

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

      return session ? <p>Session ID: {session.session_id}</p> : <p>No active session</p>;
    };
    ```
  </RequestExample>

  <ResponseExample>
    ```json Logged in theme={null}
    {
      "session": { ... },
      "isInitialized": true,
      "fromCache": false
    }
    ```

    ```json Not initialized theme={null}
    {
      "session": null,
      "isInitialized": false,
      "fromCache": false
    }
    ```

    ```json Logged out theme={null}
    {
      "session": null,
      "isInitialized": true,
      "fromCache": false
    }
    ```
  </ResponseExample>
</Panel>
