Custom Admin Role - Admin Plugin

I am trying to add an additional Admin Role to the Admin Plugin. I believe I have it set up according to the docs, but when I try to for example run authClient.admin.listUsers with my custom role, I receive the YOU_ARE_NOT_ALLOWED_TO_LIST_USERS Error. If I switch that user's role back to the default of 'admin' everything works as expected. I added screenshots of auth.ts, permissions.ts, and the function used to list users. Anyone have an idea on what I am doing wrong when creating a custom role?
No description
No description
No description
3 Replies
j_slno
j_slno•4w ago
The role is missing the required permission for the requested endpoint. Add user: ["list"] to your custom role statements.
bpurdyiv
bpurdyivOP•4w ago
I believe I am essentially doing that by spreading the ...adminAc.statements when I setup the new role. I tried doing it explicitly, like you mentioned, but still noting. Thank you tho
.
.•3w ago
aight I found the issue lol I had to go through the better auth code and debug it to find out why it's not working and realized the request headers to /admin/list-users is empty hence the permission check fails you're not gonna believe why 😂 it's called authClient for a reason, it's supposed to run on the client but you're running it in an async function that if I'm guessing correctly is called in a component that is not marked by 'use client'; directive, causing Next to attempt at fetching the users on the server, which fails because there are no admin cookies

Did you find this page helpful?