[PR #6641] feat(organization/dynamic AC): multi tenant and dynamic resources/permissions #6799

Open
opened 2026-03-13 13:12:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6641
Author: @viktormarinho
Created: 12/9/2025
Status: 🔄 Open

Base: canaryHead: dynamic-org-resources


📝 Commits (10+)

📊 Changes

12 files changed (+4196 additions, -41 deletions)

View changed files

ORGANIZATION_PLUGIN_RBAC_RESEARCH.md (+796 -0)
📝 docs/content/docs/plugins/organization.mdx (+503 -0)
e2e/smoke/test/organization-custom-resources.test.ts (+454 -0)
📝 packages/better-auth/src/plugins/organization/error-codes.ts (+18 -0)
📝 packages/better-auth/src/plugins/organization/has-permission.ts (+12 -1)
packages/better-auth/src/plugins/organization/load-resources.test.ts (+216 -0)
packages/better-auth/src/plugins/organization/load-resources.ts (+201 -0)
📝 packages/better-auth/src/plugins/organization/organization.ts (+83 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-access-control.ts (+674 -31)
packages/better-auth/src/plugins/organization/routes/crud-resources.ts (+1049 -0)
📝 packages/better-auth/src/plugins/organization/schema.ts (+55 -9)
📝 packages/better-auth/src/plugins/organization/types.ts (+135 -0)

📄 Description


Summary by cubic

Adds multi-tenant custom resources and permissions to the Organization plugin’s dynamic access control, so each org can define and enforce its own resource actions. Includes new resource CRUD endpoints, validation, caching, schema updates, docs, and tests.

  • New Features

    • Enable per-org custom resources via dynamicAccessControl.enableCustomResources.
    • New endpoints: createOrgResource, getOrgResource, listOrgResources, updateOrgResource, deleteOrgResource.
    • Organization-specific access control merges default + custom statements and is used in hasPermission.
    • Auto-expands role permissions to include newly defined custom resource actions.
    • Validation, caching, and error codes for reserved names, duplicates, limits, and malformed definitions.
    • Schema adds organizationResource with resource and permissions fields.
  • Migration

    • Run database migration to create the organizationResource model/table.
    • Opt in by setting dynamicAccessControl.enableCustomResources = true and (optionally) configure reserved names and max resources per org.

Written for commit 1497a85f12. Summary will update automatically on new commits.

Very useful for extensible applications that lets users create entities. This way, users can also create roles that have different access to their custom resources.

i'm not sure about the design of this feature. i would like input from you guys


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6641 **Author:** [@viktormarinho](https://github.com/viktormarinho) **Created:** 12/9/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `dynamic-org-resources` --- ### 📝 Commits (10+) - [`3668a58`](https://github.com/better-auth/better-auth/commit/3668a58450d17d1b6a433f845d47555293515e82) dynamic org resources - [`ee599ca`](https://github.com/better-auth/better-auth/commit/ee599ca57d6879cac9a0d4f4d2f79efe5ba45721) chore: release v1.5.0 - [`39f5504`](https://github.com/better-auth/better-auth/commit/39f5504f40f0f33ba0d15788c48b14769f995740) chore: release v1.5.1 - [`757b766`](https://github.com/better-auth/better-auth/commit/757b7669a0c2b1ff190c83b42d769be3bf4715a8) chore: release v1.5.2 - [`e67d66d`](https://github.com/better-auth/better-auth/commit/e67d66dc2da97b0846738d834dbc5b84aa475b83) chore: release v1.5.3 - [`744903e`](https://github.com/better-auth/better-auth/commit/744903ecbbbc51b5566e4423f5d318a9f517532c) chore: release v1.5.4 - [`8ea6cf9`](https://github.com/better-auth/better-auth/commit/8ea6cf95eea5aff6b2ad0d56257d5d9d9b8b186d) chore: release v1.5.5 - [`b4afd8d`](https://github.com/better-auth/better-auth/commit/b4afd8d34ae4efbcb9904428b5b2bc8a450109f2) chore: release v1.5.6 - [`988f048`](https://github.com/better-auth/better-auth/commit/988f048c86b41f442ff51a8ff68c66574c232629) chore: release v1.5.7 - [`e7b4865`](https://github.com/better-auth/better-auth/commit/e7b48654f9b2a418d5a3ff5e91bffe8ac75bdae0) chore: release v1.5.8 ### 📊 Changes **12 files changed** (+4196 additions, -41 deletions) <details> <summary>View changed files</summary> ➕ `ORGANIZATION_PLUGIN_RBAC_RESEARCH.md` (+796 -0) 📝 `docs/content/docs/plugins/organization.mdx` (+503 -0) ➕ `e2e/smoke/test/organization-custom-resources.test.ts` (+454 -0) 📝 `packages/better-auth/src/plugins/organization/error-codes.ts` (+18 -0) 📝 `packages/better-auth/src/plugins/organization/has-permission.ts` (+12 -1) ➕ `packages/better-auth/src/plugins/organization/load-resources.test.ts` (+216 -0) ➕ `packages/better-auth/src/plugins/organization/load-resources.ts` (+201 -0) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+83 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-access-control.ts` (+674 -31) ➕ `packages/better-auth/src/plugins/organization/routes/crud-resources.ts` (+1049 -0) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+55 -9) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+135 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds multi-tenant custom resources and permissions to the Organization plugin’s dynamic access control, so each org can define and enforce its own resource actions. Includes new resource CRUD endpoints, validation, caching, schema updates, docs, and tests. - **New Features** - Enable per-org custom resources via `dynamicAccessControl.enableCustomResources`. - New endpoints: `createOrgResource`, `getOrgResource`, `listOrgResources`, `updateOrgResource`, `deleteOrgResource`. - Organization-specific access control merges default + custom statements and is used in `hasPermission`. - Auto-expands role permissions to include newly defined custom resource actions. - Validation, caching, and error codes for reserved names, duplicates, limits, and malformed definitions. - Schema adds `organizationResource` with `resource` and `permissions` fields. - **Migration** - Run database migration to create the `organizationResource` model/table. - Opt in by setting `dynamicAccessControl.enableCustomResources = true` and (optionally) configure reserved names and max resources per org. <sup>Written for commit 1497a85f124cf067834bc4151a68097a1a47b05d. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> Very useful for extensible applications that lets users create entities. This way, users can also create roles that have different access to their custom resources. ## i'm not sure about the design of this feature. i would like input from you guys --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:12:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6799