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

export const OrganizationDisplay = () => {
  const stytch = useStytchB2BClient();
  const [organization, setOrganization] = useState(null);

  useEffect(() => {
    // Subscribe to organization changes
    const unsubscribe = stytch.organization.onChange((org) => {
      setOrganization(org);
    });

    // Cleanup subscription on unmount
    return unsubscribe;
  }, [stytch]);

  return (
    <div>
      {organization ? (
        <p>Organization: {organization.organization_name}</p>
      ) : (
        <p>No organization found</p>
      )}
    </div>
  );
};
{
  "email_allowed_domains": [],
  "email_invites": "ALL_ALLOWED",
  "email_jit_provisioning": "NOT_ALLOWED",
  "mfa_policy": "OPTIONAL",
  "organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
  "organization_logo_url": "",
  "organization_name": "Example Org Inc",
  "organization_slug": "exampleorg",
  "organization_external_id": "example-org-external-id",
  "sso_default_connection_id": null,
  "sso_jit_provisioning": "ALL_ALLOWED",
  "sso_jit_provisioning_allowed_connections": [],
  "sso_active_connections": [],
  "scim_active_connection": null,
  "trusted_metadata": {},
  "oauth_tenant_jit_provisioning": "RESTRICTED",
  "allowed_oauth_tenants": {
    "slack": ["T1234"],
    "hubspot": ["Hub2345", "Hub3456"]
  }
}
The Stytch SDK stores the of the logged-in in local storage. and will periodically refresh the cached data from the API. Use the organization.onChange method to listen for and react to changes to the Organization object.
Before using this method, enable in the Frontend SDK page.
If you need to asynchronously fetch guaranteed-fresh data from the API, use the organizations.get method.

Parameters

callback
function
The callback function to call when the Organization changes. The first parameter is the updated Organization object.

Return value

unsubscribe
function
The function to call to unsubscribe from the Organization change event.