Admin Plugin: Check multiple separate permission groups on one request. #1933

Closed
opened 2026-03-13 09:13:24 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @frixou89 on GitHub (Sep 15, 2025).

Is this suited for github?

  • Yes, this is suited for github

My problem at the moment is that I have a user portal that needs to use permissions to show/hide sidebar menu items.

Currently, for each menu item we make a separate request to check for that permission like so

authClient.admin.hasPermission({ permissions: {clients: ['read']} })
authClient.admin.hasPermission({ permissions: {projects: ['read']} })
...

These return a { success: boolean } response.

Describe the solution you'd like

Following the issue I described above, it would be more efficient if there was a way to check permissions 1-to-1.

For example something like this.

authClient.admin.hasPermission({
  permissions: [
    { projects: ['read'] },
    { users: ['read'], account: ['edit'] }
  ]
});

And retrieve a response like an array of the corresponding matches requested.

{
  "success": [true, false]
}

Describe alternatives you've considered

The only alternative right now is to make several API calls for each permission group which causes too many API calls.

Additional context

No response

Originally created by @frixou89 on GitHub (Sep 15, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. My problem at the moment is that I have a user portal that needs to use permissions to show/hide sidebar menu items. Currently, for each menu item we make a separate request to check for that permission like so ```ts authClient.admin.hasPermission({ permissions: {clients: ['read']} }) authClient.admin.hasPermission({ permissions: {projects: ['read']} }) ... ``` These return a `{ success: boolean }` response. ### Describe the solution you'd like Following the issue I described above, it would be more efficient if there was a way to check permissions 1-to-1. For example something like this. ```ts authClient.admin.hasPermission({ permissions: [ { projects: ['read'] }, { users: ['read'], account: ['edit'] } ] }); ``` And retrieve a response like an array of the corresponding matches requested. ```json { "success": [true, false] } ``` ### Describe alternatives you've considered The only alternative right now is to make several API calls for each permission group which causes too many API calls. ### Additional context _No response_
GiteaMirror added the enhancementplugin labels 2026-03-13 09:13:24 -05:00
Author
Owner

@hieudien14310 commented on GitHub (Sep 20, 2025):

In ur case, i think what you need is to fetch all the permissions from all the roles that a user has, and then use that to display the corresponding menu items based on roles.
If true, you can create a separate api (eg: /list-access-control) to retrieve information in the roles management section on the backend where you have configured it.

@hieudien14310 commented on GitHub (Sep 20, 2025): In ur case, i think what you need is to fetch all the permissions from all the roles that a user has, and then use that to display the corresponding menu items based on roles. If true, you can create a separate api (eg: `/list-access-control`) to retrieve information in the roles management section on the backend where you have configured it.
Author
Owner

@frixou89 commented on GitHub (Sep 20, 2025):

What I ended up with was to include the user role permissions in the customSession hook. That way I can check manually for permissions without any extra api calls. Something like that

customSession(async ({ user, session }) => {
  ...
  const userRole = (user.userRole || 'user').split(',')[0];
  const permissions =
    rolesMap[userRole as keyof typeof rolesMap]?.statements || {};

  return {
    ...userMeta,
    permissions,
  };
}

And in my sidebar component I simply check if the permission is there

items: [
  {
    ...
    hide: !permissions?.expert?.includes('list'),
  },
  {
    ...
    hide: !permissions?.client?.includes('list'),
  },
  {
    ...
    hide: !permissions?.appointment?.includes('list'),
  },
],
@frixou89 commented on GitHub (Sep 20, 2025): What I ended up with was to include the user role permissions in the `customSession` hook. That way I can check manually for permissions without any extra api calls. Something like that ```ts customSession(async ({ user, session }) => { ... const userRole = (user.userRole || 'user').split(',')[0]; const permissions = rolesMap[userRole as keyof typeof rolesMap]?.statements || {}; return { ...userMeta, permissions, }; } ``` And in my sidebar component I simply check if the permission is there ```ts items: [ { ... hide: !permissions?.expert?.includes('list'), }, { ... hide: !permissions?.client?.includes('list'), }, { ... hide: !permissions?.appointment?.includes('list'), }, ], ```
Author
Owner

@dosubot[bot] commented on GitHub (Dec 20, 2025):

Hi, @frixou89. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested an enhancement to the Admin Plugin to check multiple permission groups in a single request for better efficiency.
  • A contributor suggested fetching all permissions from user roles and creating a dedicated API endpoint for role information.
  • You shared a workaround by including user role permissions in a customSession hook to avoid extra API calls.
  • This workaround allows manual permission checks on the frontend without multiple requests and was well received.
  • The issue was effectively resolved with this approach improving efficiency.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here.
  • If I don’t hear from you within 7 days, this issue will be automatically closed.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 20, 2025): Hi, @frixou89. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested an enhancement to the Admin Plugin to check multiple permission groups in a single request for better efficiency. - A contributor suggested fetching all permissions from user roles and creating a dedicated API endpoint for role information. - You shared a workaround by including user role permissions in a customSession hook to avoid extra API calls. - This workaround allows manual permission checks on the frontend without multiple requests and was well received. - The issue was effectively resolved with this approach improving efficiency. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here. - If I don’t hear from you within 7 days, this issue will be automatically closed. Thanks for your understanding and contribution!
Author
Owner

@Gbuomprisco commented on GitHub (Dec 31, 2025):

The suggested workaround wouldn't work with DAC. I believe the original suggestion in this post would be extremely useful to everyone - and honestly, not too complex to implement.

@Gbuomprisco commented on GitHub (Dec 31, 2025): The suggested workaround wouldn't work with DAC. I believe the original suggestion in this post would be extremely useful to everyone - and honestly, not too complex to implement.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1933