[GH-ISSUE #2588] Filter user by role in authClient.admin.listUsers() #26588

Closed
opened 2026-04-17 17:13:21 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @thisisleobro on GitHub (May 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2588

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use the official admin plugin and call authClient.admin.listUsers() on the frontend

Current vs. Expected behavior

The exemple in the docs shows:

const users = await authClient.admin.listUsers({
    query: {
        searchField: "email",
        searchOperator: "contains",
        searchValue: "@example.com",
        limit: 10,
        offset: 0,
        sortBy: "createdAt",
        sortDirection: "desc",
        filterField: "role",
        filterOperator: "eq",
        filterValue: "admin",
    }
});

And by using the filter fields in the example we dont get user that have more roles than just the admin role.
Let say whe have a user that has the roles ["user", "admin"]. Those are not returned and i believe that is not the result most people expect.

Supporting 'contains' operator could solve the problem.

What version of Better Auth are you using?

^1.2.7

Provide environment information

- OS: Windows 10
- Browser: Firefox

Which area(s) are affected? (Select all that apply)

Package, Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { admin } from "better-auth/plugins"

export const auth = betterAuth({
  plugins: [
    admin()
  ],
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @thisisleobro on GitHub (May 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2588 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use the official admin plugin and call authClient.admin.listUsers() on the frontend ### Current vs. Expected behavior The exemple in the [docs](https://www.better-auth.com/docs/plugins/admin#list-users) shows: ```js const users = await authClient.admin.listUsers({ query: { searchField: "email", searchOperator: "contains", searchValue: "@example.com", limit: 10, offset: 0, sortBy: "createdAt", sortDirection: "desc", filterField: "role", filterOperator: "eq", filterValue: "admin", } }); ``` And by using the filter fields in the example we dont get user that have more roles than just the admin role. Let say whe have a user that has the roles ["user", "admin"]. Those are not returned and i believe that is not the result most people expect. Supporting 'contains' operator could solve the problem. ### What version of Better Auth are you using? ^1.2.7 ### Provide environment information ```bash - OS: Windows 10 - Browser: Firefox ``` ### Which area(s) are affected? (Select all that apply) Package, Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { admin } from "better-auth/plugins" export const auth = betterAuth({ plugins: [ admin() ], emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-17 17:13:21 -05:00
Author
Owner

@thisisleobro commented on GitHub (May 9, 2025):

Possibly related to #2472

<!-- gh-comment-id:2864923661 --> @thisisleobro commented on GitHub (May 9, 2025): Possibly related to #2472
Author
Owner

@Kinfe123 commented on GitHub (May 31, 2025):

we added a query filter contains. will be released soon

<!-- gh-comment-id:2925682474 --> @Kinfe123 commented on GitHub (May 31, 2025): we added a query filter `contains`. will be released soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26588