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

export const DiscoveryAuthenticate = () => {
  const stytch = useStytchB2BClient();
  const [searchParams] = useSearchParams();
  const [organizations, setOrganizations] = useState([]);

  useEffect(() => {
    const token = searchParams.get('token');
    if (token) {
      stytch.magicLinks.discovery.authenticate({
        discovery_magic_links_token: token,
      }).then((response) => {
        setOrganizations(response.discovered_organizations);
      });
    }
  }, [stytch, searchParams]);

  return (
    <div>
      <h2>Select an Organization</h2>
      {organizations.map((org) => (
        <div key={org.organization.organization_id}>
          {org.organization.organization_name}
        </div>
      ))}
    </div>
  );
};
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "email_address": "member@example.com",
  "discovered_organizations": [
    {
      "organization": {...},
      "membership": {
        "type": "active_member",
        "details": {},
        "member": {...}
      }
    }
  ],
  "intermediate_session_token": "intermediate-session-token-test-123"
}
magicLinks.discovery.authenticate wraps the authenticate discovery magic link endpoint. Use this method to authenticate after sending a discovery email magic link. Upon successful authentication, this method returns an and a list of discovered . The user can then select an organization and exchange the intermediate session for a full session using the exchange intermediate session method.

Parameters

data
object
required

Response

email_address
string
The email address that was authenticated.
discovered_organizations
object[]
An array of discovered Organizations that the Member can authenticate into.
intermediate_session_token
string
The intermediate session token that can be exchanged for a full session.
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.