Unable to add impersonate permission to a new role
I have a use case where I need three different roles ( user, admin, and manager ).
the manager role has to extend the impersonating permissions, but since the admin endpoint always expects the role to be admin, it always fails even tho permissions are set.
Is this some sort of a bug, or am I missing some undocumented walkthrough ?
12 Replies
Hello, may be your access control config has mistakes
No, actually there was an issue with a check that the admin plugin performs at the endpoint stage.
It only checks the adminUserIds array, and it completely ignores adminRoles.
https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/admin/has-permission.ts
GitHub
better-auth/packages/better-auth/src/plugins/admin/has-permission.t...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
admin roles should have been depricated. You should define custom roles now with custom permission set.
I check the code and its true, the auth.ap.userHasPermission, returns correct value, but api resquests such listUsers({ headers: await headers() }) returns UNAUTHORIZED:
I have my custom roles with custom permission set:
@Bo3o Bro I was trying different things, admin api only works if your role are in adminRoles prop, even if you have granted permissions to list users, delete etc...
So, you can add your role as admin and only grant unique permissions required to perform your required admin action
Yes that's exactly the issue I faced while trying to create a manager role with impersonating permission, tried it by correctly setting the roles and permission, works anywhere except for the admin api, I have modified the mentionned helper that checks the permissions to make it work with predefined adminRoles
still documented and there is no mention of deprecation
@LeMonsalve admin endpoint does not check adminRoles at all, it only checks if ther user's id exists in the adminUserIds, or if the role is the default adminRole
Yesss
We need to wait at least for v1.2.4
mind to share how you did it sir?
should be fixed on
1.2.4-beta.12
@Bo3o @LeMonsalveI just modified the has-permission helper in order to consider the roles defined under adminRoles
this is still not possible, we have bitmasks role structure and we can't integrate it with better-auth because you request your custom roles everywhere.
packages/better-auth/src/plugins/access/access.ts
user should come here. there is no special role id etc. the only thing that comes is the text ‘admin’ etc.
member and user need to be pushed all over the place.
member in roleId and user in roleId used. but dont get authorize
in roleId :/there must be something like this, but I still don't understand the structure.
