[PR #5718] feat: team roles #6175

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5718
Author: @XavierGeerinck
Created: 11/1/2025
Status: 🔄 Open

Base: canaryHead: feat/team-roles


📝 Commits (10+)

📊 Changes

9 files changed (+1150 additions, -16 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/access/statement.ts (+4 -0)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+22 -0)
📝 packages/better-auth/src/plugins/organization/error-codes.ts (+6 -0)
📝 packages/better-auth/src/plugins/organization/organization.ts (+111 -10)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+266 -0)
📝 packages/better-auth/src/plugins/organization/schema.ts (+1 -0)
packages/better-auth/src/plugins/organization/team-roles.test.ts (+705 -0)
📝 packages/better-auth/src/plugins/organization/team.test.ts (+13 -6)
📝 packages/better-auth/src/plugins/organization/types.ts (+22 -0)

📄 Description

Summary

Extends the organization plugin to support team-level roles, enabling fine-grained access control within teams. Team members can now be assigned specific roles (e.g., admin, member, viewer) with customizable permissions.

💡 Usage Example

const auth = betterAuth({
  plugins: [
    organization({
      teamRoles: {
        roles: {
          admin: { permissions: ["teamMember:*"] },
          member: { permissions: ["teamMember:read"] },
          viewer: { permissions: [] }
        },
        defaultRole: "member",
        creatorRole: "admin"
      }
    })
  ]
})

Running Tests

pnpm i
cd packages/better-auth
pnpm test src/plugins/organization/team-roles.test.ts 

Summary by cubic

Adds team-level roles to the organization plugin so teams can assign and enforce roles per member. Introduces APIs to update and read team member roles, with defaults and creator-as-admin behavior.

  • New Features
    • Configurable team roles via options.teams.teamRoles (roles, defaultRole=member, creatorRole=admin).
    • Team creators are automatically added as team admins.
    • addTeamMember accepts an optional role and falls back to default when omitted.
    • New endpoints: POST /organization/update-team-member-role and GET /organization/get-team-member.
    • hasPermission accepts an optional teamId to check team-scoped permissions, falling back to org role when not a team member.
    • Access control includes teamMember permissions (create, update, delete, read) and new error codes for role updates and visibility.
    • Team member schema now includes a role field (default "member").

Written for commit 0ef88710bf. Summary will update automatically on new commits.


🔄 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/5718 **Author:** [@XavierGeerinck](https://github.com/XavierGeerinck) **Created:** 11/1/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/team-roles` --- ### 📝 Commits (10+) - [`231ca41`](https://github.com/better-auth/better-auth/commit/231ca418cfb81513193d4eec88ab2afd2f6f63bf) base of canary - [`0bee449`](https://github.com/better-auth/better-auth/commit/0bee44947061b5f542598e9da15e6e5016d3bd17) copilot suggestions - [`8864bd1`](https://github.com/better-auth/better-auth/commit/8864bd11af74186e950ceda19db437d6c25f508f) fix tests - [`df1683b`](https://github.com/better-auth/better-auth/commit/df1683bbb574acc043e6760354e86e19d05be4a5) also add teamId to the hasPermission - [`a8ae746`](https://github.com/better-auth/better-auth/commit/a8ae7465e9b47756120815bc1b24b067640625a2) fix linting - [`c98eb62`](https://github.com/better-auth/better-auth/commit/c98eb625053883ea735838f9fd714afde00c9607) formatting issues - [`4eef006`](https://github.com/better-auth/better-auth/commit/4eef0064d24ef2c4906c968ccda1c41db0780148) linting fixes - [`9b601a1`](https://github.com/better-auth/better-auth/commit/9b601a145333dab99eb4565273bffa77daafc827) address cubic issue - [`2f1688d`](https://github.com/better-auth/better-auth/commit/2f1688dc4f15627ec507df865aeb3a5edaab6ece) linting issue - [`4ee17a4`](https://github.com/better-auth/better-auth/commit/4ee17a4403b63da2fae891fde325ae9731acb970) test fixes for team ### 📊 Changes **9 files changed** (+1150 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/access/statement.ts` (+4 -0) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+22 -0) 📝 `packages/better-auth/src/plugins/organization/error-codes.ts` (+6 -0) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+111 -10) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+266 -0) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+1 -0) ➕ `packages/better-auth/src/plugins/organization/team-roles.test.ts` (+705 -0) 📝 `packages/better-auth/src/plugins/organization/team.test.ts` (+13 -6) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+22 -0) </details> ### 📄 Description ## Summary Extends the organization plugin to support team-level roles, enabling fine-grained access control within teams. Team members can now be assigned specific roles (e.g., admin, member, viewer) with customizable permissions. ## 💡 Usage Example ```typescript const auth = betterAuth({ plugins: [ organization({ teamRoles: { roles: { admin: { permissions: ["teamMember:*"] }, member: { permissions: ["teamMember:read"] }, viewer: { permissions: [] } }, defaultRole: "member", creatorRole: "admin" } }) ] }) ``` ## Running Tests ``` pnpm i cd packages/better-auth pnpm test src/plugins/organization/team-roles.test.ts ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds team-level roles to the organization plugin so teams can assign and enforce roles per member. Introduces APIs to update and read team member roles, with defaults and creator-as-admin behavior. - **New Features** - Configurable team roles via options.teams.teamRoles (roles, defaultRole=member, creatorRole=admin). - Team creators are automatically added as team admins. - addTeamMember accepts an optional role and falls back to default when omitted. - New endpoints: POST /organization/update-team-member-role and GET /organization/get-team-member. - hasPermission accepts an optional teamId to check team-scoped permissions, falling back to org role when not a team member. - Access control includes teamMember permissions (create, update, delete, read) and new error codes for role updates and visibility. - Team member schema now includes a role field (default "member"). <sup>Written for commit 0ef88710bf5ac06690bbc5a1f8bf16f06a52cb7f. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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 12:50:08 -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#6175