# Organizations

> create_organization(attrs) with slug rules and an after-create hook, a deferred owner check, an assignment ceiling, and member functions (role change, remove, leave, transfer ownership) on the access contract.

- Category: Tenancy & accounts
- Module: `organizations`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/organizations
- Page: https://bettersupabase.com/blocks/organizations

## Install

```bash
npx better-supabase add organizations
```

The command also installs `updated-at`, `memberships`, `permissions`, `seeds`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by organizations; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    seeds: {},
    // Modes: "managed", "custom". The default is "managed".
    organizations: { mode: "managed" },
  },
});
```

## Client

The React hooks are the registry item `@better-supabase/use-organizations` (`npx shadcn add @better-supabase/use-organizations`). They return data and actions and render no UI. Source: https://github.com/ScaleDockHQ/better-supabase/blob/main/packages/registry/items/hooks/use-organizations.ts

## Events

- `organization.created`
- `organization.deleted`
- `organization.member_left`
- `organization.member_removed`
- `organization.member_resumed`
- `organization.member_suspended`
- `organization.ownership_transferred`
- `organization.role_changed`
- `organization.switched`
- `organization.updated`

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md), [seeds](https://bettersupabase.com/blocks/seeds.md), [updated-at](https://bettersupabase.com/blocks/updated-at.md)

Works with: [audit](https://bettersupabase.com/blocks/audit.md), [billing](https://bettersupabase.com/blocks/billing.md), [data-lifecycle](https://bettersupabase.com/blocks/data-lifecycle.md), [entitlements](https://bettersupabase.com/blocks/entitlements.md), [invitations](https://bettersupabase.com/blocks/invitations.md), [reserved-slugs](https://bettersupabase.com/blocks/reserved-slugs.md), [imports](https://bettersupabase.com/blocks/imports.md)

## Recipes

- [Organization switcher](https://bettersupabase.com/recipes/org-switcher.md): A menu of the user's organizations that switches the active one and refreshes the session for its tenant claim.
- [Members table](https://bettersupabase.com/recipes/members-table.md): An organization's members with their roles, where a role change shows at once and a member can be removed.
- [Workspace URL field](https://bettersupabase.com/recipes/workspace-url-field.md): An organization form with a name and a URL slug, where reserved and taken slugs come back as field errors.
