Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ishaq74/concordia/llms.txt
Use this file to discover all available pages before exploring further.
Organizations & Teams
Concordia uses Better Auth’s organization plugin to provide multi-tenant team management with role-based access control, member management, and invitation workflows.Overview
Organizations are implemented insrc/database/schemas/auth-schema.ts using Better Auth’s built-in organization features. This provides:
- Multi-user organizations with hierarchical roles
- Member invitation system
- Active organization context per session
- Organization-scoped resources (blogs, services, etc.)
Organization Schema
Fromsrc/database/schemas/auth-schema.ts (lines 94-105):
Organization Fields
Unique identifier for the organization
Display name of the organizationExample:
"Acme Corporation"Unique URL-friendly identifierExample:
"acme-corp"URL to organization logo image
When the organization was created
JSON string for additional custom data
The
slug field has a unique index ensuring no two organizations share the same URL path.Member Management
Fromauth-schema.ts (lines 107-124):
Member Fields
Unique member relationship ID
Reference to the organizationOn Delete: CASCADE - members are deleted when organization is deleted
Reference to the userOn Delete: CASCADE - membership is removed when user is deleted
Member’s role within the organizationCommon roles:
owner, admin, memberWhen the user joined the organization
Member Indexes
Two indexes optimize member queries:- By Organization:
member_organizationId_idx- Fast lookup of all members in an org - By User:
member_userId_idx- Fast lookup of all orgs a user belongs to
Invitation System
Fromauth-schema.ts (lines 126-146):
Invitation Fields
Unique invitation identifier
Organization the invitation is for
Email address of the invitee
Role the invitee will have upon accepting
Invitation status:
pending, accepted, rejected, expiredExpiration date/time for the invitation
When the invitation was created
User who sent the invitation (must be org admin/owner)
Invitation Indexes
- By Organization:
invitation_organizationId_idx- List all invitations for an org - By Email:
invitation_email_idx- Find pending invitations for a user
Session Context
Fromauth-schema.ts (lines 32-51), sessions track the active organization:
ID of the organization currently active in this sessionAllows users to switch between organizations they belong to
Users can belong to multiple organizations. The
activeOrganizationId determines which org context is used for creating resources.Relationships
Fromauth-schema.ts (lines 176-201), Drizzle relations define the connections:
Relationship Diagram
Organization Roles
Better Auth organization plugin supports hierarchical roles:Default Roles
Full control over organization, including deletion
- Manage all members and invitations
- Delete organization
- Change organization settings
- Create and manage all resources
Administrative privileges
- Invite and manage members
- Manage organization settings
- Create and manage resources
- Cannot delete organization
Basic member access
- View organization resources
- Create resources under organization
- Cannot invite users
- Cannot change settings
Custom roles can be defined in Better Auth configuration to match your specific permission requirements.
Organization-Scoped Resources
Blog Posts
Fromblog_posts.schema.ts:
Service Listings
Fromservices_listings.schema.ts:
Authors
Fromblog_authors.schema.ts:
The
worksForId field links authors to organizations, establishing organizational attribution for content.Invitation Workflow
- Create Invitation: Admin/owner creates invitation with email and role
- Send Email: System sends invitation link to email address
- User Accepts: User clicks link and accepts invitation
- Create Membership: System creates
memberrecord with specified role - Update Invitation: Invitation status changes to
accepted
Example Invitation Flow
Multi-Tenancy Pattern
Organizations enable multi-tenancy where:- Users can belong to multiple organizations
- Resources can be scoped to an organization
- Sessions track active organization context
- Permissions are enforced per organization
Switching Organizations
Users switch active organization by updating their session:Best Practices
Member Management
- Always verify user’s role before allowing privileged actions
- Use cascade deletes to maintain referential integrity
- Index lookups by both
organizationIdanduserIdfor performance
Invitation Security
- Set reasonable expiration times (7-14 days)
- Verify invitation status before acceptance
- Check that email matches authenticated user
- Clean up expired invitations periodically
Organization Isolation
- Always filter queries by organization ID
- Use session’s
activeOrganizationIdfor context - Validate user has access to organization before showing resources
- Consider using RLS (Row Level Security) policies
Integration with Better Auth
The organization plugin is configured in Better Auth setup and provides:- Automatic organization context in auth session
- Built-in member and invitation management APIs
- Role-based access control helpers
- Organization switching functionality