Auth & Organizations

Organizations & Multi-Tenancy

Build multi-tenant applications with AuthSetu Organizations, Role-Based Access Control (RBAC), and member invitations.


Organizations & Multi-Tenancy

AuthSetu provides built-in multi-tenant organization support, allowing your users to create companies, invite team members, assign granular roles, and switch contexts effortlessly.

Organization Hierarchy

text
Organization (e.g. Acme Corp)
  ├── Project A (Staging)
  │     └── Customers & API Keys
  └── Project B (Production)
        └── Customers & API Keys

---

1. Roles & Permissions (RBAC)

AuthSetu enforces strict Role-Based Access Control out of the box:

| Default Role | Description | Default Permissions |
| :--- | :--- | :--- |
| Owner | Full control over organization, billing, and team. | * (All permissions) |
| Admin | Manages team members, projects, and security settings. | org:manage, members:invite, members:delete, api_keys:manage |
| Member | Standard access to organization resources. | org:read, projects:read |

Checking Permissions in Code

tsx
import { usePermission, Protect } from "@authsetu/react";

export function MemberSettings() {
  const canInvite = usePermission("members:invite");

  return (
    <div>
      {canInvite && <button>Invite New Member</button>}

      <Protect permission="org:manage" fallback={<p>Admin permissions required.</p>}>
        <button>Update Organization Settings</button>
      </Protect>
    </div>
  );
}

---

2. Organization Switcher UI

Allow users to switch between multiple tenant organizations with the pre-built component:

tsx
import { OrganizationSwitcher } from "@authsetu/react";

export function HeaderNav() {
  return (
    <div className="flex items-center gap-4">
      <OrganizationSwitcher
        hidePersonal={false}
        afterSelectOrganizationUrl="/dashboard"
        afterCreateOrganizationUrl="/dashboard"
      />
    </div>
  );
}

---

3. Member Invitations Workflow

1. Admin sends invitation: Calls POST /api/v1/organizations/[id]/invitations or uses .
2. Invitee receives email: AuthSetu sends a signed invitation link with a verification token.
3. Acceptance: Invitee clicks the link to join the organization with their assigned role.

typescript
// Server-side API example to invite member
const response = await fetch("https://api.authsetu.com/api/v1/organizations/org_123/invitations", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    email: "new.teammate@company.com",
    role: "admin",
  }),
});


Was this page helpful?