B2B Saas Authentication

/

Frontend SDKs

/

Headless

/

Organizations

/

Get Organization

Get Organization

The SDK provides synchronous and asynchronous methods for getting the Organization of the logged-in Member. The recommended approach is to use the synchronous method, organization.getSync, and listen to changes with the organization.onChange method.

If logged in, the organization.getSync method returns the cached Organization object. Otherwise, it returns null. This method does not refresh the Organization's data.

The organization.getInfo method is similar to organization.getSync, but it returns an object containing the organization object and a fromCache boolean. If fromCache is true, the Organization object is from the cache and a state refresh is in progress.

The organization.onChange method takes in a callback that gets called whenever the Organization object changes. It returns an unsubscribe method for you to call when you no longer want to listen for such changes.

In React, the @stytch/react library provides the useStytchOrganization hook that implements these methods for you to easily access the Organization and listen for changes.

The asynchronous method, organization.get, wraps the get organization endpoint. It fetches the Organization's data and refreshes the cached object if changes are detected. The Stytch SDK will invoke this method automatically in the background, so you probably won't need to call this method directly.

import React from 'react';
import { useStytchOrganization } from '@stytch/react/b2b';

export const Home = () => {
  const { organization } = useStytchOrganization();

  return organization ? <p>Welcome to {organization.organization_name}</p> : <p>Log in to continue!</p>;
};

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "organization": {
	"email_allowed_domains": [],
	"email_invites": "ALL_ALLOWED",
	"email_jit_provisioning": "NOT_ALLOWED",
	"mfa_policy": "OPTIONAL",
	"organization_id": "organization-test-staging-12345",
	"organization_logo_url": "",
	"organization_name": "Example Org Inc",
	"organization_slug": "exampleorg",
	"sso_default_connection_id": null,
	"sso_jit_provisioning": "NOT_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"]
	}
  }
}