[GH-ISSUE #3732] Nested permission statements in admin access control plugin #27025

Closed
opened 2026-04-17 17:49:01 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @typed-sigterm on GitHub (Aug 1, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3732

Is this suited for github?

  • Yes, this is suited for github

Currently we can't define nested permissions like:

const statement = {
  'some-product': {
    'some-resource': ['some-operation']
  }
} as const

Describe the solution you'd like

 type Statements = {
-    readonly [resource: string]: readonly LiteralString[];
+   readonly [resource: string]: readonly LiteralString[] | Statements;
 };

Describe alternatives you've considered

N/A

Additional context

No response

Originally created by @typed-sigterm on GitHub (Aug 1, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3732 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently we can't define nested permissions like: ```ts const statement = { 'some-product': { 'some-resource': ['some-operation'] } } as const ``` ### Describe the solution you'd like ```diff type Statements = { - readonly [resource: string]: readonly LiteralString[]; + readonly [resource: string]: readonly LiteralString[] | Statements; }; ``` ### Describe alternatives you've considered N/A ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 17:49:02 -05:00
Author
Owner

@frectonz commented on GitHub (Aug 14, 2025):

Can you give me an example where this would be useful? I don't know why someone would need this. Can you elaborate more?

<!-- gh-comment-id:3190222600 --> @frectonz commented on GitHub (Aug 14, 2025): Can you give me an example where this would be useful? I don't know why someone would need this. Can you elaborate more?
Author
Owner

@typed-sigterm commented on GitHub (Aug 21, 2025):

Our products shares a unified authentication service, so we hopes it can support nested permission statement like:

  • web-admin
    • support-ticket
      • write
      • manage
    • blog
      • write
    • ...
  • discord-bot
    • ...
  • game
    • ...

And also, granting web-admin equals to granting all permissions under web-admin

<!-- gh-comment-id:3210721894 --> @typed-sigterm commented on GitHub (Aug 21, 2025): Our products shares a unified authentication service, so we hopes it can support nested permission statement like: - web-admin - support-ticket - write - manage - blog - write - ... - discord-bot - ... - game - ... And also, granting `web-admin` equals to granting all permissions under `web-admin`
Author
Owner

@frectonz commented on GitHub (Aug 25, 2025):

Thanks for the suggestion! We understand the use case, but the Admin plugin is intentionally designed around a flat resource → actions model. Nested or hierarchical permissions introduce a different paradigm and add complexity to the core.

The good news is that this can be implemented entirely in userland by creating separate roles for each resource and then merging them to form composite roles, like a web-admin. That way, you get the hierarchical permission structure you want while keeping the configuration flat and fully compatible with createAccessControl, without adding extra complexity to Better Auth itself.

export const statement = {
  supportTicket: ["write", "manage"],
  blog: ["write"]
} as const;

const ac = createAccessControl(statement);

export const supportTicketRole = ac.newRole({
  supportTicket: ["write", "manage"],
});

export const blogRole = ac.newRole({
  blog: ["write"],
});

// Merge roles into a single web-admin role
export const webAdmin = ac.newRole({
  ...supportTicketRole.statements,
  ...blogRole.statements,
})

For now, we don’t plan to support hierarchical permissions in core.

<!-- gh-comment-id:3220326035 --> @frectonz commented on GitHub (Aug 25, 2025): Thanks for the suggestion! We understand the use case, but the Admin plugin is intentionally designed around a flat `resource → actions` model. Nested or hierarchical permissions introduce a different paradigm and add complexity to the core. The good news is that this can be implemented entirely in userland by creating separate roles for each resource and then merging them to form composite roles, like a web-admin. That way, you get the hierarchical permission structure you want while keeping the configuration flat and fully compatible with `createAccessControl`, without adding extra complexity to Better Auth itself. ```typescript export const statement = { supportTicket: ["write", "manage"], blog: ["write"] } as const; const ac = createAccessControl(statement); export const supportTicketRole = ac.newRole({ supportTicket: ["write", "manage"], }); export const blogRole = ac.newRole({ blog: ["write"], }); // Merge roles into a single web-admin role export const webAdmin = ac.newRole({ ...supportTicketRole.statements, ...blogRole.statements, }) ``` For now, we don’t plan to support hierarchical permissions in core.
Author
Owner

@typed-sigterm commented on GitHub (Aug 25, 2025):

Thanks for the detailed reply! What about #3270?

<!-- gh-comment-id:3220444825 --> @typed-sigterm commented on GitHub (Aug 25, 2025): Thanks for the detailed reply! What about #3270?
Author
Owner

@frectonz commented on GitHub (Aug 25, 2025):

I will take a look at it.

<!-- gh-comment-id:3220584808 --> @frectonz commented on GitHub (Aug 25, 2025): I will take a look at it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27025