Admin not authorized

I am trying to list users with the admin plugin but even when my users only role is "admin" I get a 401 from the endpoint. What could I be missing?
Solution:
I fixed it. I had the role imported as a different name because the plugin is named admin. I renamed the plugin import and it started working.
Jump to solution
3 Replies
Ping
Ping3mo ago
Can you show me how you're calling the method?
coder2000
coder2000OP3mo ago
async function loadUsers() {
// Get all users
const { data: users } = await authClient.admin.listUsers({
query: {
limit: pageSize,
offset: (currentPage - 1) * pageSize,
},
});
setUsers(users?.users as UserWithRole[]);
setTotal(users?.total || 0);
}

useEffect(() => {
loadUsers();
});
async function loadUsers() {
// Get all users
const { data: users } = await authClient.admin.listUsers({
query: {
limit: pageSize,
offset: (currentPage - 1) * pageSize,
},
});
setUsers(users?.users as UserWithRole[]);
setTotal(users?.total || 0);
}

useEffect(() => {
loadUsers();
});
@Ping Any insights? I didn't think I was using it wrong. Is there a middleware I need to set on load?
Solution
coder2000
coder20003mo ago
I fixed it. I had the role imported as a different name because the plugin is named admin. I renamed the plugin import and it started working.

Did you find this page helpful?