Skip to main content

Overview

Session tokens are valid for one organization at a time, but you can exchange a member’s active session for a session with another organization using the Session exchange endpoint:

Build an organization switcher

See our example apps for a code example of an organization switcher component.
1

List organizations the user has access to

Use the discovery.organizations.list() method to retrieve a list of organizations the user has access to:
export const listOrganizations = async () => {
    const { discovered_organizations } = await stytch.discovery.organizations.list();
    return discovered_organizations;
};
2

Exchange the active session

Once the user selects an organization, exchange their active session for a session in the selected organization using the session.exchange() method:
export const exchange = (target_organization_id) => {
    stytch.session.exchange({
        organization_id: target_organization_id,
        session_duration_minutes: DESIRED_SESSION_LENGTH,
    });
};

Notes

  • If additional authentication is required for the selected organization, the Exchange session method returns an intermediate_session_token instead of a fully minted session.