Skip to content

Add Multi-Organization protocol support for B2B SaaS multi-tenancy - #56

Merged
huangyiirene merged 2 commits into
mainfrom
copilot/add-organization-support
Jan 21, 2026
Merged

Add Multi-Organization protocol support for B2B SaaS multi-tenancy#56
huangyiirene merged 2 commits into
mainfrom
copilot/add-organization-support

Conversation

CopilotAI commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Adds native protocol support for multi-tenant B2B SaaS architectures where users belong to multiple organizations/workspaces, aligning with better-auth's organization plugin capabilities.

Changes

New Schemas (system/organization.zod.ts)

  • Organization: Core tenant model with slug (unique URL identifier), logo, and extensible metadata
  • Member: User-to-organization mapping with flexible role strings (owner, admin, member, etc.)
  • Invitation: Workflow support with status enum (pending/accepted/rejected/expired) and expiresAt expiry

Session Context Switching

Added activeOrganizationId?: string to SessionSchema for tenant context tracking across requests.

Auth Configuration

New optional organization block in AuthConfigSchema:

constauthConfig: AuthConfig={// ... existing configorganization: {enabled: true,allowUserToCreateOrg: true,// User vs admin-only org creationdefaultRole: 'member',// Role for invited memberscreatorRole: 'owner',// Role for org creator}}

Schema Design Notes

  • Organization slug enforces [a-z0-9_-]+ pattern for URL-safe routing
  • Member role uses flexible strings vs enums to support custom RBAC schemes
  • All IDs are opaque strings to support various backend implementations
Original prompt

Based on the refactoring work in PR #55 of objectstack-ai/spec, I need to implement the Multi-Organization architecture in the protocol to align with better-auth capabilities.

Please update the spec files to include Organization support.

Requirements:

  1. Create packages/spec/src/system/organization.zod.ts:

    • Define OrganizationSchema: id, name, slug (unique), logo, metadata, timestamps.
    • Define MemberSchema: id, organizationId, userId, role (string), timestamps.
    • Define InvitationSchema: id, organizationId, email, role, status (pending/accepted/rejected), expiresAt, inviterId.
  2. Update packages/spec/src/system/identity.zod.ts:

    • Add activeOrganizationId (optional string) to SessionSchema. This is crucial for context switching in multi-tenant apps.
  3. Update packages/spec/src/system/auth.zod.ts:

    • Add an organization configuration block to AuthConfigSchema:
      organization: z.object({enabled: z.boolean().default(false),allowUserToCreateOrg: z.boolean().default(true),defaultRole: z.string().default('member'),creatorRole: z.string().default('owner'),}).optional()
  4. Export everything: Ensure the new file is exported in packages/spec/src/index.ts.

This addition ensures ObjectStack protocol natively supports B2B SaaS scenarios where users belong to multiple teams/workspaces.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercelBot commented Jan 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
specErrorErrorJan 21, 2026 11:36am

Request Review

- Created organization.zod.ts with OrganizationSchema, MemberSchema, and InvitationSchema
- Updated SessionSchema to include activeOrganizationId for context switching
- Added organization configuration block to AuthConfigSchema
- Exported organization schemas in index.ts
- Added comprehensive tests for all new schemas
- Generated JSON schemas and documentation
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
CopilotAI changed the title [WIP] Add Multi-Organization architecture support in protocolAdd Multi-Organization protocol support for B2B SaaS multi-tenancyJan 21, 2026
CopilotAI requested a review from hotlongJanuary 21, 2026 11:37
@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation protocol:system tests size/l labels Jan 21, 2026
@huangyiirene
huangyiirene marked this pull request as ready for review January 21, 2026 12:11
@huangyiirene
huangyiirene merged commit 749fcbf into mainJan 21, 2026
9 of 10 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationprotocol:systemsize/ltests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@huangyiirene@hotlong