[GH-ISSUE #5990] Admin list users — multi-field search support #19026

Open
opened 2026-04-15 17:48:11 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Yasser5711 on GitHub (Nov 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5990

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

In the current /admin/list-users endpoint, the search functionality only allows searching in a single field using searchField.

When working with custom user models that include additional fields (e.g., firstName, lastName, username, etc.), or when trying to build richer admin UIs, it's limiting to only be able to search in one field at a time.

This causes frustration when building search bars that should match across multiple fields simultaneously (email + name, or email + firstName + lastName, etc.).

Describe the solution you'd like

Add support for multi-field search through two new optional query parameters:

1. searchInFields?: string[]

  • When provided, the admin API should search across all specified fields.

  • Only applied when searchField is not set.

  • Example:

    searchInFields: ["email", "name", "firstName"]
    

2. searchMode?: "OR" | "AND"

  • Determines how searchInFields are combined.
  • "OR" (default): match if any field contains the search value
  • "AND": match only if all fields contain the search value

Example request

/admin/list-users?searchValue=john&searchInFields=email,firstName,lastName&searchMode=OR

This would return users where email OR firstName OR lastName contains "john".

Expected benefits

  • Much more powerful admin search functionality
  • Works automatically with additional fields defined using inferAdditionalFields
  • More intuitive search experience for admin dashboards
  • Backward compatible

Describe alternatives you've considered

  • Client-side filtering: Not scalable; requires fetching all users (impossible with pagination).
  • Combining multiple requests (one per field): Inefficient, requires deduplication and merging client-side.
  • Joining fields into a single computed DB column: Complicated and undocumented; still doesn't solve AND vs OR logic.

None of these alternatives provide the simplicity or clean API shape of adding multi-field search support directly in the backend.

Additional context

This feature would integrate cleanly into the existing listUsers API and remain fully backward-compatible.

The implementation is straightforward:

  • Extend Zod schema in the admin plugin
  • Build multiple where conditions when searchInFields is present
  • Support OR or AND logic in the internal adapter
Originally created by @Yasser5711 on GitHub (Nov 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5990 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. In the current `/admin/list-users` endpoint, the search functionality only allows searching in a *single* field using `searchField`. When working with custom user models that include additional fields (e.g., `firstName`, `lastName`, `username`, etc.), or when trying to build richer admin UIs, it's limiting to only be able to search in one field at a time. This causes frustration when building search bars that should match across multiple fields simultaneously (email + name, or email + firstName + lastName, etc.). ### Describe the solution you'd like Add support for **multi-field search** through two new optional query parameters: #### **1. `searchInFields?: string[]`** * When provided, the admin API should search across all specified fields. * Only applied when `searchField` is *not* set. * Example: ```ts searchInFields: ["email", "name", "firstName"] ``` #### **2. `searchMode?: "OR" | "AND"`** * Determines how `searchInFields` are combined. * `"OR"` (default): match if *any* field contains the search value * `"AND"`: match only if *all* fields contain the search value #### Example request ``` /admin/list-users?searchValue=john&searchInFields=email,firstName,lastName&searchMode=OR ``` This would return users where **email OR firstName OR lastName** contains `"john"`. #### Expected benefits * Much more powerful admin search functionality * Works automatically with additional fields defined using `inferAdditionalFields` * More intuitive search experience for admin dashboards * Backward compatible ### Describe alternatives you've considered * **Client-side filtering**: Not scalable; requires fetching all users (impossible with pagination). * **Combining multiple requests** (one per field): Inefficient, requires deduplication and merging client-side. * **Joining fields into a single computed DB column**: Complicated and undocumented; still doesn't solve AND vs OR logic. None of these alternatives provide the simplicity or clean API shape of adding multi-field search support directly in the backend. ### Additional context This feature would integrate cleanly into the existing `listUsers` API and remain fully backward-compatible. The implementation is straightforward: * Extend Zod schema in the admin plugin * Build multiple `where` conditions when `searchInFields` is present * Support OR or AND logic in the internal adapter
GiteaMirror added the enhancementorganization labels 2026-04-15 17:48:11 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 14, 2025):

Hi there, thanks for the detailed feature request! Based on your description, we recommend extending the Zod schema in the admin plugin to accept a new query parameter (searchInFields) and an optional searchMode to combine the search terms. This approach would allow the backend to build multiple where conditions—using OR or AND logic—when searchInFields is provided, while leaving the existing searchField functionality intact for backward compatibility [1].

To move forward, you could prototype this by updating the query validation schema in the admin route and modifying the adapter to generate a combined query for the specified fields. Have you already started any work in this area or testing any preliminary implementation, and is there anything specific causing issues in your current setup?

tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3533567194 --> @better-auth-agent[bot] commented on GitHub (Nov 14, 2025): Hi there, thanks for the detailed feature request! Based on your description, we recommend extending the Zod schema in the admin plugin to accept a new query parameter (searchInFields) and an optional searchMode to combine the search terms. This approach would allow the backend to build multiple where conditions—using OR or AND logic—when searchInFields is provided, while leaving the existing searchField functionality intact for backward compatibility [[1]](https://www.better-auth.com/docs/reference/contributing). To move forward, you could prototype this by updating the query validation schema in the admin route and modifying the adapter to generate a combined query for the specified fields. Have you already started any work in this area or testing any preliminary implementation, and is there anything specific causing issues in your current setup? tag @better-auth-agent if you would like an answer from the Agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 13, 2026):

Hi, @Yasser5711. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested multi-field search support for the /admin/list-users endpoint with new query parameters searchInFields and searchMode to allow AND/OR logic.
  • The maintainer responded positively, suggesting schema and adapter extensions to support multiple where conditions while keeping backward compatibility.
  • The maintainer inquired if you had started implementation or faced any issues.
  • No updates or further comments have been posted since.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I don’t hear back within 7 days, I will automatically close the issue.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3898032187 --> @dosubot[bot] commented on GitHub (Feb 13, 2026): Hi, @Yasser5711. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested multi-field search support for the `/admin/list-users` endpoint with new query parameters `searchInFields` and `searchMode` to allow AND/OR logic. - The maintainer responded positively, suggesting schema and adapter extensions to support multiple where conditions while keeping backward compatibility. - The maintainer inquired if you had started implementation or faced any issues. - No updates or further comments have been posted since. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I don’t hear back within 7 days, I will automatically close the issue. Thanks for your understanding and contribution!
Author
Owner

@ceolinwill commented on GitHub (Feb 13, 2026):

This feature is still relevant

<!-- gh-comment-id:3898109463 --> @ceolinwill commented on GitHub (Feb 13, 2026): This feature is still relevant
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19026