[PR #7839] [CLOSED] fix: handle falsy filter values in admin listUsers API #15832

Closed
opened 2026-04-13 10:15:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7839
Author: @liuxiaopai-ai
Created: 2/7/2026
Status: Closed

Base: canaryHead: fix/admin-list-users-falsy-filter


📝 Commits (1)

  • 47145e1 fix: handle falsy filter values in admin listUsers API

📊 Changes

2 files changed (+53 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/admin/admin.test.ts (+51 -0)
📝 packages/better-auth/src/plugins/admin/routes.ts (+2 -2)

📄 Description

Summary

Fixes #7837

The listUsers API in the admin plugin was ignoring falsy filter values (false, 0, "") because the code used a truthy check (if (ctx.query?.filterValue)) to determine whether to apply the filter. This caused valid filter values like false, 0, and empty string to be silently skipped.

Changes

  • packages/better-auth/src/plugins/admin/routes.ts: Changed both filterValue and searchValue checks from truthy checks to strict !== undefined && !== null checks, so falsy values are properly handled.
  • packages/better-auth/src/plugins/admin/admin.test.ts: Added test case covering filterValue = false, filterValue = 0, and filterValue = "" to ensure they are not ignored.

Before

if (ctx.query?.filterValue) {  // skips false, 0, ""

After

if (ctx.query?.filterValue !== undefined && ctx.query?.filterValue !== null) {  // only skips undefined/null

Summary by cubic

Fixes listUsers in the admin plugin to correctly apply filters when values are falsy (false, 0, ""), so valid filters are no longer ignored and search behaves as expected.

  • Bug Fixes
    • Use explicit undefined/null checks for filterValue and searchValue instead of truthy checks.
    • Add tests covering false, 0, and empty string to ensure filters are applied and prevent regressions.

Written for commit 47145e12d9. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7839 **Author:** [@liuxiaopai-ai](https://github.com/liuxiaopai-ai) **Created:** 2/7/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/admin-list-users-falsy-filter` --- ### 📝 Commits (1) - [`47145e1`](https://github.com/better-auth/better-auth/commit/47145e12d9a12689fe590987373564b68c5cad63) fix: handle falsy filter values in admin listUsers API ### 📊 Changes **2 files changed** (+53 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+51 -0) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+2 -2) </details> ### 📄 Description ## Summary Fixes #7837 The `listUsers` API in the admin plugin was ignoring falsy filter values (`false`, `0`, `""`) because the code used a truthy check (`if (ctx.query?.filterValue)`) to determine whether to apply the filter. This caused valid filter values like `false`, `0`, and empty string to be silently skipped. ## Changes - **`packages/better-auth/src/plugins/admin/routes.ts`**: Changed both `filterValue` and `searchValue` checks from truthy checks to strict `!== undefined && !== null` checks, so falsy values are properly handled. - **`packages/better-auth/src/plugins/admin/admin.test.ts`**: Added test case covering `filterValue = false`, `filterValue = 0`, and `filterValue = ""` to ensure they are not ignored. ## Before ```typescript if (ctx.query?.filterValue) { // skips false, 0, "" ``` ## After ```typescript if (ctx.query?.filterValue !== undefined && ctx.query?.filterValue !== null) { // only skips undefined/null ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes listUsers in the admin plugin to correctly apply filters when values are falsy (false, 0, ""), so valid filters are no longer ignored and search behaves as expected. - **Bug Fixes** - Use explicit undefined/null checks for filterValue and searchValue instead of truthy checks. - Add tests covering false, 0, and empty string to ensure filters are applied and prevent regressions. <sup>Written for commit 47145e12d9a12689fe590987373564b68c5cad63. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:15:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15832