filterField in admin.listUsers

what is filterField used for in admin.listUsers
10 Replies
M Zeeshan
M ZeeshanOP2mo ago
@Better Auth what is filterField used for in admin.listUsers
Better Auth
Better Auth2mo ago
The filterField option is used to indicate which field of the user record you want to apply your filter on when you call admin.listUsers(). For example, if you set filterField: "role" along with a matching operator (like "eq") and a corresponding filterValue, the query will return only those users whose role exactly matches the specified value [1][2]. This helps narrow down the result set based on a particular attribute of the users in your database. Sources: 1. Filter user by role in authClient.admin.listUsers() 2. Admin | Better Auth
GitHub
Filter user by role in authClient.admin.listUsers() · Issue #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 ...
Admin | Better Auth
Admin plugin for Better Auth
M Zeeshan
M ZeeshanOP2mo ago
@Better Auth what if want to filter morethan one value, e.g. i want all users else role admin and moderators
Better Auth
Better Auth2mo ago
You can achieve multi‐value filtering by using the new "where" clause support that was recently added to the admin plugin. Instead of relying on the basic filterField/filterOperator options—which work for single values—you can build more complex filters. For example, if you want to exclude users with roles "admin" and "moderators", you could write something like this:
const users = await authClient.admin.listUsers({
query: {
where: {
role: {
notIn: ['admin', 'moderators']
}
}
}
});
const users = await authClient.admin.listUsers({
query: {
where: {
role: {
notIn: ['admin', 'moderators']
}
}
}
});
This approach gives you the flexibility to specify multiple roles. Note that using operators like "ne" directly for multiple values might not work as expected with some backends (see issues with Prisma [15]). The "where" clause is designed exactly for these multi-value scenarios [12]. Sources: 15. NE filter operator not working with Prisma 12. feat: add 'where' clause support to add filters in the list users, admin plugin
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
NE filter operator not working with Prisma · Issue #2468 · better...
Is this suited for github? Yes, this is suited for github To Reproduce This is the query i'm using: await authClient.admin.listUsers( { query: { filterField: "role", filterOperator: &...
GitHub
feat: add 'where' clause support to add filters in the list users, ...
This PR is to add the option to filter the users in the function listUsers for the admin plugin.
M Zeeshan
M ZeeshanOP2mo ago
@Better Auth yeah i can see pr was merged but vscode does not show intellesence for filter or where clause
Better Auth
Better Auth2mo ago
Hi there! The merged PR added full support for the "where" clause (as seen in [1]), but sometimes VSCode’s IntelliSense can lag behind, especially if the TypeScript language server hasn’t picked up on the updated type definitions. Here are a few tips you might try: 1. Verify that you’re using the latest released version of Better Auth (or the specific commit if you’re testing a branch) so that the new types are included. 2. Restart your VSCode or its TS server to force it to reload the updated type declarations. 3. Double-check your project’s dependency lock file to ensure there’s no cache of an older version. If the issue persists after these steps, please let us know so we can investigate further. Happy coding! Sources: 1. feat: add 'where' clause support to add filters in the list users, admin plugin
GitHub
feat: add 'where' clause support to add filters in the list users, ...
This PR is to add the option to filter the users in the function listUsers for the admin plugin.
M Zeeshan
M ZeeshanOP2mo ago
@Better Auth would i open issue for it
Better Auth
Better Auth2mo ago
Hey there! If you've encountered unexpected behavior or believe there's room for improvement—even if it seems minor—opening an issue on our GitHub is a great way to let us know. Make sure to include clear steps to reproduce the problem or describe your feature request in detail, similar to how others have reported issues like the access token refresh [4] or cookie caching problem [9]. This helps our team investigate and address your concern efficiently. Happy coding! Sources: 4. Feature Request: Implement Access Token Exposure and Automated Refresh for First-Party Application Support 9. Better Auth cookies caching from Expo app (client) to Next JS API (server)
GitHub
Feature Request: Implement Access Token Exposure and Automated Refr...
Is this suited for github? Yes, this is suited for github Is your feature request related to a problem? Please describe. Currently, better-auth appears optimized for third-party OIDC authentication...
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
Better Auth cookies caching from Expo app (client) to Next JS API (...
Is this suited for github? Yes, this is suited for github To Reproduce To reproduce Step 1: Setup Better Auth with Expo + Next.js // lib/auth/auth.js import { betterAuth } from "better-auth&qu...
M Zeeshan
M ZeeshanOP2mo ago
@Better Auth why this does not work
const res = await authClient.admin.listUsers({
query: {
limit: 50,
searchValue: value,
searchField: 'email',
searchOperator: 'contains',
filterField: 'role',
filterOperator: 'eq',
filterValue: 'user',
},
});
const res = await authClient.admin.listUsers({
query: {
limit: 50,
searchValue: value,
searchField: 'email',
searchOperator: 'contains',
filterField: 'role',
filterOperator: 'eq',
filterValue: 'user',
},
});
Better Auth
Better Auth2mo ago
It’s likely that the issue is related to how the filtering works on the role field. In Better Auth, when using filterOperator "eq", it only matches users whose role exactly equals "user". If a user has multiple roles (for example, ["user", "admin"]), they won’t be returned by this filter [1]. If you intend to match any user where "user" is present in an array of roles, you’d need to use the "contains" operator. There’s an open discussion about adding support for the "contains" operator for filtering by role, which would allow you to catch users with multiple roles [4]. So, if your use case involves users with more than one role, adjusting the filter operator (once that support is available) should resolve the issue. Sources: 1. Filter user by role in authClient.admin.listUsers() 4. Allow filtering users from using 'contains' operator
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
Filter user by role in authClient.admin.listUsers() · Issue #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 ...
GitHub
Allow filtering users from using 'contains' operator by thisisleobr...
Motivation to allow 'contains' was so that i could filter by role when calling authClient.admin.listUsers(). Currently 'eq' (equals) is the only valid operator for f...

Did you find this page helpful?