Member

Once a Member has successfully logged in, the SDK can be used to view information about the Organization they belong to. In addition, the Member may update and delete the Organization if their Role gives them permissions to do so. To learn more about our RBAC implementation, see our RBAC guide.

Methods

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-native/b2b';

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

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

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_connections": [],
	"trusted_metadata": {}
  }
}

Delete Organization

The Delete Organization method wraps the delete organization API endpoint. This will delete the logged-in Member's Organization. As a consequence, their Member object will also be deleted, and their session will be revoked.

This method is not available for unauthenticated end users. In order to call this method, there must be a valid Member Session containing the necessary Role to complete this action. This method requires the Member to have permission to perform the delete action on the stytch.organization Resource.

In addition, Member actions & permissions must be enabled in the SDK Configuration page of the Stytch dashboard. To learn more about our RBAC implementation, see our RBAC guide.

import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const DeleteOrganization = () => {
  const stytch = useStytchB2BClient();

  const deleteOrganization = () => {
    stytch.organization.delete();
  };

  return <button onClick={deleteOrganization}>Delete your Organization</button>;
};

RESPONSE

200
{
    "status_code": 200,
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
  }

Update Organization

The update organization method wraps the update organization API endpoint. This will update the logged-in Member's Organization.

This method is not available for unauthenticated end users. In order to call this method, there must be a valid Member Session containing the necessary Role to complete this action. The specific permissions needed depend on which of the optional fields are passed in the request. For example, if the organization_name argument is provided, the Member must have permission to perform the update.info.name action on the stytch.organization Resource.

In addition, Member actions & permissions must be enabled in the SDK Configuration page of the Stytch dashboard. To learn more about our RBAC implementation, see our RBAC guide.


Method parameters


organization_namestring

organization_slugstring

organization_logo_urlstring

email_jit_provisioningstring

email_invitesstring

email_allowed_domainsarray[strings]

sso_default_connection_idstring

sso_jit_provisioningstring

sso_jit_provisioning_allowed_connectionsarray[strings]

auth_methodsstring

allowed_auth_methodsarray[strings]

mfa_methodsstring

allowed_mfa_methodsarray[strings]

mfa_policystring

rbac_email_implicit_role_assignmentsarray[object]
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const UpdateOrganizationName = () => {
  const stytch = useStytchB2BClient();

  const updateOrganization = () => {
    stytch.organization.update({
      organization_name: 'Example Org Inc.',
    });
  };

  return <button onClick={updateOrganization}>Update your Organization's Name</button>;
};

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": "ALL_ALLOWED",
	"mfa_policy": "OPTIONAL",
	"organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
	"organization_logo_url": "",
	"organization_name": "Example Org Inc.",
	"organization_slug": "example-org",
	"sso_default_connection_id": null,
	"sso_jit_provisioning": "ALL_ALLOWED",
	"sso_jit_provisioning_allowed_connections": [],
	"sso_active_connections": [],
	"scim_active_connections": [],
	"trusted_metadata": {},
	"auth_methods": "ALL_ALLOWED",
    "allowed_auth_methods": []
  }
}