Skip to main content
import { useEffect, useState } from 'react';
import { useStytchB2BClient } from '@stytch/react/b2b';

export const DiscoveryAuthenticate = () => {
  const stytch = useStytchB2BClient();
  const [discoveredOrganizations, setDiscoveredOrganizations] = useState([]);

  useEffect(() => {
    const getDiscoveredOrganizations = async () => {
      const { discovered_organizations } = await stytch.discovery.organizations.list();
      setDiscoveredOrganizations(discovered_organizations);
    };
    getDiscoveredOrganizations();
  }, [stytch]);

  return (
    <div>
      <h1>Select an Organization</h1>
      <ul>
        {discoveredOrganizations.map((organization) => (
          <li key={organization.organization_id}>{organization.organization_name}</li>
        ))}
      </ul>
    </div>
  );
};
{
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "status_code": 200,
  "email_address": "nstam@stytch.com",
  "discovered_organizations": [
    {
      "organization": {
        "organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
        "organization_name": "Example Org Inc"
      },
      "membership": { ... },
      "member_authenticated": true,
      "primary_required": { ... },
      "mfa_required": { ... }
    },
    {
      "organization": {
        "organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
        "organization_name": "Example Org Inc"
      },
      "membership": { ... },
      "member_authenticated": false,
      "primary_required": { ... },
      "mfa_required": { ... }
    }
  ],
  "organization_id_hint": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931"
}
The discovery.organizations.list method wraps the List Organizations API endpoint. Use it to list all possible organization given the current Member Session or . If there is a current Member Session, the SDK will call the endpoint with the session token. Otherwise, the SDK will use the intermediate session token. If neither a Member Session nor an intermediate session token is present, this method will fail.

Response

email_address
string
The email corresponding to the current intermediate_session_token, session_token, or session_jwt.
discovered_organizations
array[objects]
An array of Discovered Organizations.
organization_id_hint
string | null
The organization_id that the intermediate session token is associated with, if any. This field will be null if a session_token or session_jwt is passed in.
request_id
string
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
status_code
number
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.