> ## 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.

# useStytchMemberSession Hook

> Get the current Member session using the Stytch Next.js SDK

export const organization = "Represents an instance or tenant in your application, typically mapping to each of your top-level customers.";

export const member = "Represents an individual end user's account within a given Organization, uniquely identified within that Organization by their email address.";

export const isReactNative_0 = undefined

To get the active session of the currently signed in <Tooltip tip={member}>Member</Tooltip>, use the `useStytchMemberSession` hook.

If the user is not signed in, the returned value will be `null`.

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

In non-React environments, use the [`session.getSync`](../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="member_session_id" type="string">
      Globally unique UUID that identifies the Session.
    </ResponseField>

    <ResponseField name="member_id" type="string">
      Globally unique UUID that identifies a specific Member.
    </ResponseField>

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

      <Expandable title="properties">
        <ResponseField name="type" type="string">
          The type of authentication factor. The possible values are: `email_otp`, `impersonated`, `imported`, `magic_link`, `oauth`, `otp`, `password`, `recovery_codes`, `sso`, `trusted_auth_token`, or `totp`.
        </ResponseField>

        <ResponseField name="delivery_method" type="string">
          The method that was used to deliver the authentication factor. The possible values depend on the type:

          * `email_otp`: Only `email`.
          * `impersonated`: Only `impersonation`.
          * `imported`:  Only `imported_auth0`.
          * `magic_link`: Only `email`.
          * `oauth`: `oauth_google`, `oauth_microsoft`, `oauth_hubspot`, `oauth_slack`, or `oauth_github`.
            You may see an 'exchange' delivery method when a non-email-verifying OAuth factor originally authenticated in one organization is exchanged for a factor in another organization. This can happen during authentication flows such as [session exchange](/api-reference/b2b/api/sessions/exchange-session). The non-email-verifying OAuth providers are Hubspot, Slack, and Github. Google is also considered non-email-verifying when the HD claim is empty. The possible exchange values are `oauth_exchange_google`, `oauth_exchange_hubspot`, `oauth_exchange_slack`, or `oauth_exchange_github`. The final possible value is `oauth_access_token_exchange`, if this factor came from an [access token exchange flow](/api-reference/b2b/api/sessions/exchange-access-token).
            * `otp`: Only `sms`.
            * `password`: Only `knowledge`.
            * `recovery_codes`: Only `recovery_code`.
            * `sso`: `sso_saml` or `sso_oidc`.
            * `trusted_auth_token`: Only `trusted_token_exchange`.
            * `totp`: Only `authenticator_app`.
        </ResponseField>

        <ResponseField name="created_at" type="string">
          The timestamp when the factor was initially authenticated.
        </ResponseField>

        <ResponseField name="last_authenticated_at" type="string">
          The timestamp when the factor was last authenticated.
        </ResponseField>

        <ResponseField name="updated_at" type="string">
          The timestamp when the factor was last updated.
        </ResponseField>

        <ResponseField name="sequence_order" type="string">
          Either `PRIMARY` or `SECONDARY`. Secondary factor types include `otp`, `totp`, and `recovery_codes`. All other factors are primary.
        </ResponseField>

        <ResponseField name="email_factor" type="object">
          Information about the email factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="email_address" type="string">
              The email address of the Member.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="phone_number_factor" type="object">
          Information about the phone number factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="phone_number" type="string">
              The phone number.
            </ResponseField>

            <ResponseField name="phone_id" type="string">
              The globally unique UUID of the phone number.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="google_oauth_factor" type="object">
          Information about the Google OAuth factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of the OAuth registration.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>

            <ResponseField name="provider_subject" type="string">
              The unique identifier for the User within the OAuth provider. Also commonly called the sub or "Subject field" in OAuth protocols.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="microsoft_oauth_factor" type="object">
          Information about the Microsoft OAuth factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of the OAuth registration.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>

            <ResponseField name="provider_subject" type="string">
              The unique identifier for the User within the OAuth provider. Also commonly called the sub or "Subject field" in OAuth protocols.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="hubspot_oauth_factor" type="object">
          Information about the Hubspot OAuth factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of the OAuth registration.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>

            <ResponseField name="provider_subject" type="string">
              The unique identifier for the User within the OAuth provider. Also commonly called the sub or "Subject field" in OAuth protocols.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="github_oauth_factor" type="object">
          Information about the Github OAuth factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of the OAuth registration.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>

            <ResponseField name="provider_subject" type="string">
              The unique identifier for the User within the OAuth provider. Also commonly called the sub or "Subject field" in OAuth protocols.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="slack_oauth_factor" type="object">
          Information about the Slack OAuth factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of the OAuth registration.
            </ResponseField>

            <ResponseField name="email_id" type="string">
              The globally unique UUID of the Member's email.
            </ResponseField>

            <ResponseField name="provider_subject" type="string">
              The unique identifier for the User within the OAuth provider. Also commonly called the sub or "Subject field" in OAuth protocols.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="google_oauth_exchange_factor" type="object">
          Information about the Google OAuth Exchange factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="email_id" type="string">
              The globally unique UUID of the email address.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="hubspot_oauth_exchange_factor" type="object">
          Information about the Hubspot OAuth Exchange factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="email_id" type="string">
              The globally unique UUID of the email address.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="github_oauth_exchange_factor" type="object">
          Information about the Github OAuth Exchange factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="email_id" type="string">
              The globally unique UUID of the email address.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="slack_oauth_exchange_factor" type="object">
          Information about the Slack OAuth Exchange factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="email_id" type="string">
              The globally unique UUID of the email address.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="saml_sso_factor" type="object">
          Information about the SAML SSO factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of an SSO Registration.
            </ResponseField>

            <ResponseField name="provider_id" type="string">
              Globally unique UUID that identifies a specific SAML Connection.
            </ResponseField>

            <ResponseField name="external_id" type="string">
              The ID of the member given by the identity provider.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="oidc_sso_factor" type="object">
          Information about the OIDC SSO factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              The unique ID of an SSO Registration.
            </ResponseField>

            <ResponseField name="provider_id" type="string">
              Globally unique UUID that identifies a specific OIDC Connection.
            </ResponseField>

            <ResponseField name="external_id" type="string">
              The ID of the member given by the identity provider.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="authenticator_app_factor" type="object">
          Information about the TOTP-backed Authenticator App factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="totp_id" type="string">
              Globally unique UUID that identifies the TOTP instance.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="impersonated_factor" type="object">
          Information about the impersonated factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="impersonator_id" type="string">
              For impersonated sessions initiated via the Stytch Dashboard, the impersonator's Stytch Dashboard `member_id`.
            </ResponseField>

            <ResponseField name="impersonator_email_address" type="string">
              The email address of the impersonator.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="trusted_auth_token_factor" type="object">
          Information about the trusted auth token factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="token_id" type="string">
              The ID of the trusted auth token.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="oauth_access_token_exchange_factor" type="object">
          Information about the access token exchange factor, if one is present.

          <Expandable title="properties">
            <ResponseField name="client_id" type="string">
              The ID of the Connected App client.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="organization_id">
      The globally unique UUID that identifies the Organization associated with the Session.
    </ResponseField>

    <ResponseField name="organization_slug">
      The unique URL slug of the Organization associated with the Session.
    </ResponseField>

    <ResponseField name="roles" type="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.
    </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="custom_claims" type="map<string, any>">
      The custom claims map for a Session. Claims can be added to a Session during a Sessions authenticate call.
    </ResponseField>
  </Expandable>
</ResponseField>

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

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

<Panel>
  <RequestExample>
    ```jsx Next.js theme={null}
    '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>
      );
    };
    ```
  </RequestExample>
</Panel>
