• ShipSaaSDocumentation
  • Introduction
  • Getting Started
    • Installation
    • Environment Setup
    • Database Setup
    • Development Guide
  • Database
    • Repository Pattern
    • Drizzle Queries
    • Migration Workflow
    • Drizzle Studio
    • Best Practices
  • File Management
    • File Upload Component
    • Server Actions
    • Storage Configuration
  • Authentication Methods
    • Credentials Authentication
    • Magic Link Authentication
    • Two-Factor Authentication (2FA)
    • Social Authentication
    • API Keys & Bearer Tokens
    • Organizations (Multi-tenant)
  • Authorization & Permissions
    • Roles & Hierarchy
    • Route Protection
    • API Protection
    • CASL Permissions
  • Email & Notifications
    • Resend Setup
    • React Email Templates
    • Notification System
    • Email Workflows
    • Customization & Extension
  • Stripe & Payments
    • Stripe Setup
    • Better Auth Integration
    • Checkout Methods
    • Subscription Management
    • Admin Dashboard
    • Webhook Events
  • Architecture & Development
    • Presentation Layer
    • Service Layer
    • Persistence Layer
    • Helpers Architecture
    • Project Structure
    • Development Workflow
  • Testing
    • General Testing
    • Unit Testing
    • UI Component Testing
    • Repository Testing
    • Service Testing
    • End-to-End Testing
  • Deployment
    • Vercel Deployment
    • GitHub Actions CI/CD
    • Database Backup & Restore
    • Database Migrations
    • Troubleshooting Deployment
  • AI Agents Integration
  • Blog Management
    • Blog Setup
    • MDX Blog
    • Database Blog
  • Async Tasks
    • Setup
    • Email Workflows
    • Payment Processing
    • Maintenance Jobs
  1. Documentation
  2. Authentication Methods
  3. Organizations (Multi-tenant)
Buydocschangelogsdemocommunity

Organizations (Multi-tenant)

PreviousAPI Keys & Bearer TokensNextAuthorization & Permissions
On this page
How to ActivateHow Organizations WorkMulti-tenant ConceptOrganization ManagementCreating OrganizationsOrganization SettingsMember ManagementInviting MembersMember Roles & PermissionsInvitation ManagementBilling Mode ImpactOrganization Billing vs User BillingSubscription ManagementBetter Auth ConfigurationOrganization Pages StructureUser Experience FlowsCreating and Managing OrganizationSwitching OrganizationsCommon Issues & SolutionsSecurity & PermissionsTesting Checklist

Organizations enable multi-tenant functionality where users can create workspaces, invite team members, and collaborate with role-based permissions.

Perfect for: SaaS applications, team collaboration tools, B2B platforms, and enterprise applications.

How to Activate

1

Enable organization mode

bash
# Set billing mode to organization-based
NEXT_PUBLIC_BILLING_MODE="organization"

# Enable organization pages
NEXT_PUBLIC_ENABLED_PAGES="organization,invitation,account,settings,subscription"

# Email service required for invitations
RESEND_API_KEY="re_your_resend_api_key"
EMAIL_FROM="noreply@yourdomain.com"
2

That's it!

Organization features automatically appear in user account at /[locale]/account/organizations.

Organizations list interface

How Organizations Work

Multi-tenant Concept

Key concept: One user can belong to multiple organizations with different roles in each organization.

Organization structure:

  • Owner - Full control, billing, can delete organization
  • Admin - Manage members, settings, but cannot delete
  • Member - Basic access, use organization features

User experience:

  • Users switch between organizations
  • Each organization has its own data and settings
  • Invitations allow users to join multiple organizations

Organization Selection Interface:

Organization selection dropdown interface

Organization Management

Creating Organizations

1

Go to organizations page

User visits /[locale]/account/organizations to see all their organizations.

2

Create new organization

Click "Create Organization" button (if user has permission).

3

Set organization details

  • Name: Organization display name
  • Description: Optional description
  • Settings: Initial configuration
4

User becomes owner

Creator automatically becomes the organization owner with full permissions.

Creation limits: By default, users cannot create organizations (allowUserToCreateOrganization: false). Only admins can create organizations, or this setting can be changed.

Organization Settings

Location: /[locale]/account/organizations/[id]/edit

Available settings:

  • Basic info - Name, description, avatar
  • Member management - Invite, remove, change roles
  • Billing settings - Subscription management (if enabled)
  • Danger zone - Delete organization (owner only)

Organization Members Management:

Organization members management interface

Member Roles Management:

Change member roles interface

Member Management

Inviting Members

1

Go to organization settings

Organization owner/admin visits /[locale]/account/organizations/[id] and clicks "Invite Members".

2

Send invitation

  • Enter email address of person to invite
  • Select role (Admin or Member)
  • Add optional invitation message
Organization member invitation interface
3

Invitation email sent

Invitee receives email with invitation link and organization details.

4

Accept invitation

Invitee clicks link, goes to /[locale]/account/invitations/[id], and can accept or decline.

Organization invitation acceptance interface

Member Roles & Permissions

Full organization control:

  • Manage all settings and members
  • Handle billing and subscriptions
  • Delete organization
  • Transfer ownership
  • Cannot be removed by others

Limitations: Only one owner per organization

Management permissions:

  • Invite and remove members
  • Change member roles (except owner)
  • Modify organization settings
  • Access admin features

Cannot: Delete organization or change billing

Basic access:

  • Use organization features
  • View organization content
  • Collaborate with team
  • View member list

Cannot: Invite members or change settings

Invitation Management

Invitation limits: 10 pending invitations per organization (configurable)

Invitation features:

  • Pending invitations - Track sent invitations
  • Expiration - Invitations expire after set time
  • Resend - Can resend invitations if needed
  • Cancel - Can cancel pending invitations

User invitation page: /[locale]/account/invitations

  • View all pending invitations
  • Accept or decline each invitation
  • See organization details before joining

Detailed Members Management Interface:

Detailed organization members interface

Billing Mode Impact

Organization Billing vs User Billing

bash
NEXT_PUBLIC_BILLING_MODE="organization"

How it works:

  • Organization pays for subscriptions
  • Owner/Admin manages billing
  • All members benefit from organization's subscription
  • Per-organization pricing model

Best for: Team subscriptions, B2B SaaS, collaborative tools

bash
NEXT_PUBLIC_BILLING_MODE="user"

How it works:

  • Individual users pay for their own subscriptions
  • Personal accounts with individual billing
  • No shared organization subscriptions
  • Per-user pricing model

Best for: Individual tools, personal productivity, B2C apps

Subscription Management

With organization billing:

  • Subscriptions are attached to organizations
  • Only owners can manage billing
  • Members benefit from organization subscription
  • Usage/limits are per-organization

Subscription pages:

  • /[locale]/account/billing/subscription - Current organization's subscription
  • Organization switching affects which subscription is shown

Better Auth Configuration

The organization system uses Better Auth's organization plugin:

typescript
// In src/lib/better-auth/auth.ts
organization({
  invitationLimit: 10,              // Max pending invitations
  membershipLimit: 10,              // Max members per organization
  allowUserToCreateOrganization: false,  // Only admins can create

  async sendInvitationEmail(data) {
    const inviteLink = `${env.NEXT_PUBLIC_APP_URL}/invitations/${data.id}`

    // Send via notification service
    await createTypedNotificationService({
      userId: invitedUser.id,
      type: NotificationTypeConst.organization_invitation,
      metadata: {
        organizationId: data.organization.id,
        organizationName: data.organization.name,
        invitedBy: data.inviter.user.name,
        role: data.role,
      }
    })
  }
})

Key configuration:

  • Invitation limit: 10 pending invitations per organization
  • Member limit: 10 members per organization
  • User creation: Disabled by default (admin-only)
  • Email notifications: Automatic via notification service

Organization Pages Structure

src/app/[locale]/(app)/account/
├── organizations/
│   ├── page.tsx                    # List all user's organizations
│   └── [id]/
│       ├── page.tsx                # Organization details & members
│       └── edit/
│           └── page.tsx            # Organization settings
└── invitations/
    ├── page.tsx                    # List pending invitations
    └── [id]/
        └── page.tsx                # Accept/decline specific invitation

User Experience Flows

Creating and Managing Organization

1

Create organization

Admin creates organization from /[locale]/account/organizations.

2

Invite team members

Owner goes to organization settings and invites members by email.

3

Members join

Invited users receive emails, visit invitation page, and accept to join.

4

Collaborate

All organization members can now access shared organization features and data.

Switching Organizations

User can:

  • View all organizations they belong to
  • Switch active organization context
  • See different data/settings per organization
  • Have different roles in different organizations

Common Issues & Solutions

"Cannot create organization" error?

  • Check allowUserToCreateOrganization setting
  • Verify user has admin permissions
  • Ensure organization limits not exceeded
  • Check if feature is enabled in pages config

Invitation emails not arriving?

  • Verify RESEND_API_KEY is configured
  • Check EMAIL_FROM domain is verified
  • Look in spam/junk folders
  • Ensure notification service is working

Organization features not visible?

  • Check NEXT_PUBLIC_BILLING_MODE="organization"
  • Verify NEXT_PUBLIC_ENABLED_PAGES includes "organization,invitation"
  • Restart server after environment changes
  • Ensure user is logged in and verified

Security & Permissions

Built-in security features:

  • Role-based access control (RBAC)
  • Invitation token validation
  • Member limits prevent abuse
  • Owner-only sensitive operations

Permission validation:

  • All organization operations check user roles
  • API endpoints validate organization membership
  • UI shows/hides features based on permissions
  • Database queries filter by organization access

Administration Interface:

Organization administration back-office interface

Testing Checklist

1

Test organization creation

  1. Create new organization (if permitted)
  2. Verify user becomes owner
  3. Test organization settings page
  4. Update organization details
2

Test member invitations

  1. Invite member by email
  2. Check invitation email is sent
  3. Accept invitation with different user
  4. Verify member appears in organization
3

Test role management

  1. Change member roles
  2. Test permission differences
  3. Try removing members
  4. Test owner-only operations
4

Test billing integration

  1. Check subscription shows for organization
  2. Test billing management (owner only)
  3. Verify member benefits from org subscription

All working? Your application now supports full multi-tenant organizations with team management and role-based permissions!