clanker.net
PRODUCTIVITY better-auth/skills

organization-best-practices

Configure multi-tenant organizations, manage members and invitations, define custom roles and permissions, set up teams, and implement RBAC using Better Auth's organization plugin. Use when users need org setup, team management, member roles, access control, or the Better Auth organization plugin.

PRODUCTIVITY
USE THIS SKILL

DOWNLOAD THE APP TO INSTALL AND USE /organization ON YOUR DEVICE

Scan to open on your device
QR code for organization-best-practices Opens skill content in Expo Go
COMMAND
/organization
CATEGORY
Productivity
REPOSITORY
better-auth/skills
COMMIT

SKILL PROMPT

--- name: organization-best-practices description: Configure multi-tenant organizations, manage members and invitations, define custom roles and permissions, set up teams, and implement RBAC using Better Auth's organization plugin. Use when users need org setup, team management, member roles, access control, or the Better Auth organization plugin. --- ## Setup 1. Add `organization()` plugin to server config 2. Add `organizationClient()` plugin to client config 3. Run `npx @better-auth/cli migrate` 4. Verify: check that organization, member, invitation tables exist in your database ```ts import { betterAuth } from "better-auth"; import { organization } from "better-auth/plugins"; export const auth = betterAuth({ plugins: [ organization({ allowUserToCreateOrganization: true, organizationLimit: 5, // Max orgs per user membershipLimit: 100, // Max members per org }), ], }); ``` ### Client-Side Setup ```ts import { createAuthClient } from "better-auth/client"; import { organizationClient } from "better-auth/client/plugins"; export const authClient = createAuthClient({ plugins: [organizationClient()], }); ``` ## Creating Organizations The creator is automatically assigned the `owner` role. ```ts const createOrg = async () => { const { data, error } = await authClient.organization.create({ name: "My Company", slug: "my-company", logo: "https://example.com/logo.png", metadata: { plan: "pro" }, }); }; ``` ### Controlling Organization Creation Restrict who can create organizations based on user attributes: ```ts organization({ allowUserToCreateOrganization: async (user) => { return user.emailVerified === true; }, organizationLimit: async (user) => { // Premium users get more organizations return user.plan === "premium" ? 20 : 3; }, }); ``` ### Creating Organizations on Behalf of Users Administrators can create organizations for other users (server-side only): ```ts await auth.api.createOrg [... prompt truncated for preview ...]