User is not able to ban user, even when he is admin of the org

getting {"message":"Only admins can access this endpoint","code":"ONLY_ADMINS_CAN_ACCESS_THIS_ENDPOINT"} , when client calls await admin.banUser({ userId: values.userId });
3 Replies
anand248
anand248OP5mo ago
I am confused about this particular condition in the source code - https://github.com/better-auth/better-auth/blob/58ad15dd52aafc747fb8e176b4af2ac573ff2d84/packages/better-auth/src/plugins/admin/index.ts#L85C24-L85C33
if (
!user.role ||
(Array.isArray(opts.adminRole)
? !opts.adminRole.includes(user.role)
: user.role !== opts.adminRole)
) {
throw new APIError("FORBIDDEN", {
message: "Only admins can access this endpoint",
});
}
if (
!user.role ||
(Array.isArray(opts.adminRole)
? !opts.adminRole.includes(user.role)
: user.role !== opts.adminRole)
) {
throw new APIError("FORBIDDEN", {
message: "Only admins can access this endpoint",
});
}
Where do we provide opts , I am intending to - Owner will create org and and will invite many users, he will appoint one of the user as admin (this sets the membership.role as admin , that user should be able to ban user as well.
GitHub
better-auth/packages/better-auth/src/plugins/admin/index.ts at 58ad...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
anand248
anand248OP5mo ago
I get it now. It is user.role and opts come from what is passed to admin plugin while configuring as below
betterAuth({
plugins: [
admin({
adminRole: ["admin", "orgAdmin"],
}),
...
betterAuth({
plugins: [
admin({
adminRole: ["admin", "orgAdmin"],
}),
...
I am yet to figure out, how to set this custom role of orgAdmin at user table while sending him invite. so that he can ban user
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?