Demo
General
Organizations

Overview

Learn how organizations work in the starter kit.

Organizations are a way to share data between users. Organizations can have members with different roles and permissions.

In the starter kit, organizations are handled by Better Auth and therefore you have full control over the organization management and all data is stored in the database.

How Organizations Work

Organizations enable multi-tenancy in your application. Users can:

  • Create organizations - Users can create their own organizations
  • Join organizations - Users can be invited to join organizations
  • Switch between organizations - Users can be members of multiple organizations
  • Have different roles - Users can have different roles in different organizations

Active Organization

The active organization is stored in the Better Auth session. The activeOrganizationId is available in session.activeOrganizationId and can be accessed using Better Auth's hooks and APIs.

This approach provides several benefits:

  1. Session-based - The active organization persists across page navigations
  2. Simple access - Use authClient.useActiveOrganization() on the client or getSession() on the server
  3. Automatic scoping - tRPC's protectedOrganizationProcedure automatically uses the active organization
  4. Consistent state - The active organization is managed by Better Auth and stays in sync

Roles

Organizations support the following roles:

  • Owner - Full control over the organization
  • Admin - Can manage members and organization settings
  • Member - Can access organization data

A user can have different roles in different organizations.