[GH-ISSUE #5380] Docs: Clarify relationship between adminRoles and custom access control #18857

Closed
opened 2026-04-15 17:32:44 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @elitan on GitHub (Oct 17, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5380

Issue Description

The admin plugin documentation needs clarification on when adminRoles is required vs when custom access control is sufficient.

Current Documentation Gap

The docs contain what appears to be conflicting guidance:

  1. In the Options section, there's a warning:

    "Any role that isn't in the adminRoles list, even if they have the permission, will not be considered an admin."

  2. In the Access Control section, it shows how to define custom roles with specific permissions using ac and roles.

  3. The docs don't explicitly state whether adminRoles is still required when using custom access control.

Real-World Scenario

I want my manager role to have impersonation permissions. Based on the docs, I can:

// permissions.ts
export const manager = ac.newRole({
  ...adminAc.statements, // Gives all admin permissions including impersonate
});

// auth.ts
admin({
  ac,
  roles: { manager, admin, user }
})

Question: Do I still need adminRoles: ['admin', 'manager'] here, or does the custom access control replace it?

Suggested Solution

Add a subsection in the Access Control documentation that explicitly states:

"Using Custom Access Control Without adminRoles"

When you define custom roles with access control:

  • The adminRoles option [is/is not] required
  • The custom role definitions in roles [do/do not] replace the default role checking
  • [Provide clear example of the recommended approach]

OR

"Combining adminRoles with Custom Access Control"

When using both options together:

  • adminRoles determines which roles can access admin endpoints
  • Custom access control defines granular permissions within those admin roles
  • [Provide clear example]

Impact

Without this clarity, developers may:

  • Add redundant configuration
  • Accidentally block intended admin access
  • Not understand which approach to use for their use case
Originally created by @elitan on GitHub (Oct 17, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5380 ## Issue Description The admin plugin documentation needs clarification on when `adminRoles` is required vs when custom access control is sufficient. ## Current Documentation Gap The docs contain what appears to be conflicting guidance: 1. **In the Options section**, there's a warning: > "Any role that isn't in the `adminRoles` list, even if they have the permission, will not be considered an admin." 2. **In the Access Control section**, it shows how to define custom roles with specific permissions using `ac` and `roles`. 3. **The docs don't explicitly state** whether `adminRoles` is still required when using custom access control. ## Real-World Scenario I want my `manager` role to have impersonation permissions. Based on the docs, I can: ```ts // permissions.ts export const manager = ac.newRole({ ...adminAc.statements, // Gives all admin permissions including impersonate }); // auth.ts admin({ ac, roles: { manager, admin, user } }) ``` **Question:** Do I still need `adminRoles: ['admin', 'manager']` here, or does the custom access control replace it? ## Suggested Solution Add a subsection in the Access Control documentation that explicitly states: ### "Using Custom Access Control Without adminRoles" When you define custom roles with access control: - The `adminRoles` option [is/is not] required - The custom role definitions in `roles` [do/do not] replace the default role checking - [Provide clear example of the recommended approach] OR ### "Combining adminRoles with Custom Access Control" When using both options together: - `adminRoles` determines which roles can access admin endpoints - Custom access control defines granular permissions within those admin roles - [Provide clear example] ## Impact Without this clarity, developers may: - Add redundant configuration - Accidentally block intended admin access - Not understand which approach to use for their use case
GiteaMirror added the locked label 2026-04-15 17:32:44 -05:00
Author
Owner

@elitan commented on GitHub (Oct 17, 2025):

Update: Confirmed Behavior

I've tested this and can confirm:

** is NOT required when using custom access control.**

Working Configuration

// permissions.ts
export const manager = ac.newRole({
  ...adminAc.statements, // Gives all admin permissions
});

// auth.ts
admin({
  ac,
  roles: {
    admin: adminRole,
    manager,
    user,
  },
  // No adminRoles needed!
})

This allows users with role: 'manager' to impersonate and perform all admin operations.

Documentation Suggestion

The warning about adminRoles in the Options section should clarify it only applies when NOT using custom access control:

Note: Any role that isn't in the adminRoles list, even if they have the permission, will not be considered an admin. This option is not required when using custom access control - roles defined via ac and roles will have the permissions you explicitly grant them.

<!-- gh-comment-id:3415072751 --> @elitan commented on GitHub (Oct 17, 2025): ## Update: Confirmed Behavior I've tested this and can confirm: ** is NOT required when using custom access control.** ### Working Configuration ```ts // permissions.ts export const manager = ac.newRole({ ...adminAc.statements, // Gives all admin permissions }); // auth.ts admin({ ac, roles: { admin: adminRole, manager, user, }, // No adminRoles needed! }) ``` This allows users with `role: 'manager'` to impersonate and perform all admin operations. ### Documentation Suggestion The warning about `adminRoles` in the Options section should clarify it only applies when NOT using custom access control: > **Note:** Any role that isn't in the `adminRoles` list, even if they have the permission, will not be considered an admin. **This option is not required when using custom access control** - roles defined via `ac` and `roles` will have the permissions you explicitly grant them.
Author
Owner

@elitan commented on GitHub (Oct 17, 2025):

Update: Confirmed Behavior

I've tested this and can confirm: adminRoles is NOT required when using custom access control.

The working configuration is to just define roles via ac.newRole() with the desired permissions, and the adminRoles option can be omitted entirely.

This means the warning in the docs only applies when NOT using custom access control.

<!-- gh-comment-id:3415073203 --> @elitan commented on GitHub (Oct 17, 2025): Update: Confirmed Behavior I've tested this and can confirm: adminRoles is NOT required when using custom access control. The working configuration is to just define roles via ac.newRole() with the desired permissions, and the adminRoles option can be omitted entirely. This means the warning in the docs only applies when NOT using custom access control.
Author
Owner

@2803media commented on GitHub (Oct 22, 2025):

@elitan did you test

plugins: [
    admin({
      roles: ["super_root"],
      adminRoles: ["super_root"],
      impersonationSessionDuration: 60 * 60 * 24, // 24h
    }),
  ],

without custom permissions? I can't find a way to make it work

<!-- gh-comment-id:3432869128 --> @2803media commented on GitHub (Oct 22, 2025): @elitan did you test ``` plugins: [ admin({ roles: ["super_root"], adminRoles: ["super_root"], impersonationSessionDuration: 60 * 60 * 24, // 24h }), ], ``` without custom permissions? I can't find a way to make it work
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18857