Skip to main content

useOrganizationList

The useOrganizationList hook provides methods for managing organizations the user is a member of, including creating, updating, deleting organizations, and managing members, roles, invitations, and domains.

Return Value

organizations
Organization[]
List of organizations the user is a member of
loading
boolean
Whether data is loading
error
Error | null
Any error that occurred
refetch
leaveOrganization
createOrganization
updateOrganization
deleteOrganization
getOrganizationMembers
removeOrganizationMember
getOrganizationRoles
addRoleToOrganizationMember
removeRoleFromOrganizationMember
getOrganizationInvitations
inviteOrganizationMember
discardOrganizationInvitation
resendOrganizationInvitation
getOrganizationDomains
addOrganizationDomain
verifyOrganizationDomain
removeOrganizationDomain
getEnterpriseConnections
createEnterpriseConnection
updateEnterpriseConnection
deleteEnterpriseConnection
testEnterpriseConnection

Data Structures

Examples

Basic Organization List

import { useOrganizationList } from "@wacht/nextjs";

function OrganizationsPage() {
  const { organizations, loading, createOrganization } = useOrganizationList();

  const handleCreate = async () => {
    await createOrganization({
      name: "Acme Inc",
      description: "My company",
    });
  };

  return (
    <div>
      {organizations.map((org) => (
        <div key={org.id}>{org.name}</div>
      ))}
      <button onClick={handleCreate}>Create Organization</button>
    </div>
  );
}

CRUD Operations

Create Organization

await createOrganization({
  name: "Acme Inc",
  description: "My company description",
  image: file, // Optional File object
});

Update Organization

await updateOrganization(organization, {
  name: "New Name",
  description: "New description",
  image: file,
});

Delete Organization

await deleteOrganization(organization);

Leave Organization

await leaveOrganization(organization);

Invite Member

await inviteOrganizationMember(organization, {
  email: "user@example.com",
  organizationRole: { id: "role_id" },
  workspace: { id: "workspace_id" },
  workspaceRole: { id: "workspace_role_id" },
});

Enterprise SSO

Create SSO Connection

await createEnterpriseConnection(organization, {
  protocol: "saml",
  idp_entity_id: "https://idp.example.com/entity_id",
  idp_sso_url: "https://idp.example.com/sso",
  idp_certificate: "-----BEGIN CERTIFICATE-----\n...",
  jit_enabled: true,
});

Test SSO Connection

const result = await testEnterpriseConnectionConfig(organization, {
  protocol: "saml",
  idp_entity_id: "https://idp.example.com/entity_id",
  idp_sso_url: "https://idp.example.com/sso",
  idp_certificate: "-----BEGIN CERTIFICATE-----\n...",
});

// result.success: boolean
// result.checks: { [key: string]: boolean }
// result.errors?: { [key: string]: string }

SCIM Token Management

// Generate SCIM token
const tokenInfo = await generateSCIMToken(organization, connectionId);

// Get SCIM token
const tokenInfo = await getSCIMToken(organization, connectionId);

// Revoke SCIM token
await revokeSCIMToken(organization, connectionId);