[GH-ISSUE #754] Admin plugin: using filterOperator with "ne" on listUsers returns a 500 error #25735

Closed
opened 2026-04-17 16:00:14 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @dpflucas on GitHub (Dec 3, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/754

Describe the bug

If I do

const response = await authClient.admin.listUsers({
  query: {
    sortBy: 'createdAt',
    sortDirection: 'desc',
    filterField: 'role',
    filterOperator: 'eq',
    filterValue: 'user',
  },
  fetchOptions: {
    headers: await headers(),
  },
})

it works fine, however if I change eq to ne it returns an error:

 ERROR   TypeError The "payload" argument must be of type object. Received null                                                                                                                                                Better Auth

  at cloneSourceMapV3 (node:internal/source_map/source_map:365:3)
  at new SourceMap (node:internal/source_map/source_map:145:21)
  at findSourceMap (node:internal/source_map/source_map_cache:352:17)
  at getSourcemappedFrameIfPossible (node_modules/next/dist/server/patch-error-inspect.js:101:59)
  at parseAndSourceMap (node_modules/next/dist/server/patch-error-inspect.js:165:39)
  at node_modules/next/dist/server/patch-error-inspect.js:195:30
  at AsyncLocalStorage.exit (node:async_hooks:358:14)
  at Error.<computed> (node_modules/next/dist/server/patch-error-inspect.js:188:67)
  at formatValue (node:internal/util/inspect:806:19)
  at inspect (node:internal/util/inspect:365:10)
  at formatWithOptionsInternal (node:internal/util/inspect:2304:40)
  at formatWithOptions (node:internal/util/inspect:2166:10)
  at console.value (node:internal/console/constructor:339:14)
  at console.log (node:internal/console/constructor:384:61)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093)
  at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774)
  at .next/server/chunks/node_modules_better-auth_dist_3b9074._.js:12342:36
  at async handle (.next/server/chunks/node_modules_f73693._.js:924:23)
  at async Te.a.<computed> (.next/server/chunks/node_modules_better-auth_dist_3b9074._.js:3197:17)
  at async handler (.next/server/chunks/node_modules_f73693._.js:1134:32)
  at async handler (.next/server/chunks/node_modules_f73693._.js:1185:25)
  at async AppRouteRouteModule.do (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:33313)
  at async AppRouteRouteModule.handle (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:40382)
  at async doRender (node_modules/next/dist/server/base-server.js:1455:42)
  at async responseGenerator (node_modules/next/dist/server/base-server.js:1814:28)
  at async DevServer.renderToResponseWithComponentsImpl (node_modules/next/dist/server/base-server.js:1824:28)
  at async DevServer.renderPageComponent (node_modules/next/dist/server/base-server.js:2240:24)
  at async DevServer.renderToResponseImpl (node_modules/next/dist/server/base-server.js:2278:32)
  at async DevServer.pipeImpl (node_modules/next/dist/server/base-server.js:960:25)
  at async NextNodeServer.handleCatchallRenderRequest (node_modules/next/dist/server/next-server.js:281:17)
  at async DevServer.handleRequestImpl (node_modules/next/dist/server/base-server.js:853:17)
  at async node_modules/next/dist/server/dev/next-dev-server.js:373:20
  at async Span.traceAsyncFn (node_modules/next/dist/trace/trace.js:153:20)
  at async DevServer.handleRequest (node_modules/next/dist/server/dev/next-dev-server.js:370:24)
  at async invokeRender (node_modules/next/dist/server/lib/router-server.js:183:21)
  at async handleRequest (node_modules/next/dist/server/lib/router-server.js:360:24)
  at async requestHandlerImpl (node_modules/next/dist/server/lib/router-server.js:384:13)
  at async Server.requestListener (node_modules/next/dist/server/lib/start-server.js:142:13)

 GET /api/auth/admin/list-users?sortBy=createdAt&sortDirection=desc&filterField=role&filterOperator=ne&filterValue=user 500 in 59ms

Expected behavior
It should return no error and the list of users correctly filtered.

Desktop (please complete the following information):

  • OS: macOS Sequoia 15.0
  • Browser: Chrome
  • Version: Version 131.0.6778.70 (Official Build) (arm64)

Additional context

Here's my betterAuth initialization:

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: false,
    sendResetPassword: async ({ user, url, token }, request) => {
      await sendResetPasswordEmail(user as User, url, token)
    },
  },
  plugins: [admin()],
})
Originally created by @dpflucas on GitHub (Dec 3, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/754 **Describe the bug** If I do ```ts const response = await authClient.admin.listUsers({ query: { sortBy: 'createdAt', sortDirection: 'desc', filterField: 'role', filterOperator: 'eq', filterValue: 'user', }, fetchOptions: { headers: await headers(), }, }) ``` it works fine, however if I change `eq` to `ne` it returns an error: ``` ERROR TypeError The "payload" argument must be of type object. Received null Better Auth at cloneSourceMapV3 (node:internal/source_map/source_map:365:3) at new SourceMap (node:internal/source_map/source_map:145:21) at findSourceMap (node:internal/source_map/source_map_cache:352:17) at getSourcemappedFrameIfPossible (node_modules/next/dist/server/patch-error-inspect.js:101:59) at parseAndSourceMap (node_modules/next/dist/server/patch-error-inspect.js:165:39) at node_modules/next/dist/server/patch-error-inspect.js:195:30 at AsyncLocalStorage.exit (node:async_hooks:358:14) at Error.<computed> (node_modules/next/dist/server/patch-error-inspect.js:188:67) at formatValue (node:internal/util/inspect:806:19) at inspect (node:internal/util/inspect:365:10) at formatWithOptionsInternal (node:internal/util/inspect:2304:40) at formatWithOptions (node:internal/util/inspect:2166:10) at console.value (node:internal/console/constructor:339:14) at console.log (node:internal/console/constructor:384:61) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:98:12093) at console.log (node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:106:12774) at .next/server/chunks/node_modules_better-auth_dist_3b9074._.js:12342:36 at async handle (.next/server/chunks/node_modules_f73693._.js:924:23) at async Te.a.<computed> (.next/server/chunks/node_modules_better-auth_dist_3b9074._.js:3197:17) at async handler (.next/server/chunks/node_modules_f73693._.js:1134:32) at async handler (.next/server/chunks/node_modules_f73693._.js:1185:25) at async AppRouteRouteModule.do (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:33313) at async AppRouteRouteModule.handle (node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:40382) at async doRender (node_modules/next/dist/server/base-server.js:1455:42) at async responseGenerator (node_modules/next/dist/server/base-server.js:1814:28) at async DevServer.renderToResponseWithComponentsImpl (node_modules/next/dist/server/base-server.js:1824:28) at async DevServer.renderPageComponent (node_modules/next/dist/server/base-server.js:2240:24) at async DevServer.renderToResponseImpl (node_modules/next/dist/server/base-server.js:2278:32) at async DevServer.pipeImpl (node_modules/next/dist/server/base-server.js:960:25) at async NextNodeServer.handleCatchallRenderRequest (node_modules/next/dist/server/next-server.js:281:17) at async DevServer.handleRequestImpl (node_modules/next/dist/server/base-server.js:853:17) at async node_modules/next/dist/server/dev/next-dev-server.js:373:20 at async Span.traceAsyncFn (node_modules/next/dist/trace/trace.js:153:20) at async DevServer.handleRequest (node_modules/next/dist/server/dev/next-dev-server.js:370:24) at async invokeRender (node_modules/next/dist/server/lib/router-server.js:183:21) at async handleRequest (node_modules/next/dist/server/lib/router-server.js:360:24) at async requestHandlerImpl (node_modules/next/dist/server/lib/router-server.js:384:13) at async Server.requestListener (node_modules/next/dist/server/lib/start-server.js:142:13) GET /api/auth/admin/list-users?sortBy=createdAt&sortDirection=desc&filterField=role&filterOperator=ne&filterValue=user 500 in 59ms ``` **Expected behavior** It should return no error and the list of users correctly filtered. **Desktop (please complete the following information):** - OS: macOS Sequoia 15.0 - Browser: Chrome - Version: Version 131.0.6778.70 (Official Build) (arm64) **Additional context** Here's my betterAuth initialization: ```ts export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), emailAndPassword: { enabled: true, requireEmailVerification: false, sendResetPassword: async ({ user, url, token }, request) => { await sendResetPasswordEmail(user as User, url, token) }, }, plugins: [admin()], }) ```
GiteaMirror added the locked label 2026-04-17 16:00:14 -05:00
Author
Owner
<!-- gh-comment-id:2586801786 --> @Bekacru commented on GitHub (Jan 13, 2025): https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/admin/admin.test.ts#L334-L350 this now passes
Author
Owner

@dpflucas commented on GitHub (Jan 13, 2025):

https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/admin/admin.test.ts#L334-L350

this now passes

I just updated better-auth to the latest version and still get the same error:

 GET /admin/users 200 in 2474ms
2025-01-13T11:56:17.890Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] {
  code: 'ERR_INVALID_ARG_TYPE'
}
 GET /api/auth/admin/list-users?sortBy=createdAt&sortDirection=desc&filterField=role&filterOperator=ne&filterValue=user 500 in 499ms
<!-- gh-comment-id:2586916592 --> @dpflucas commented on GitHub (Jan 13, 2025): >https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/admin/admin.test.ts#L334-L350 > > this now passes I just updated `better-auth` to the latest version and still get the same error: ``` GET /admin/users 200 in 2474ms 2025-01-13T11:56:17.890Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] { code: 'ERR_INVALID_ARG_TYPE' } GET /api/auth/admin/list-users?sortBy=createdAt&sortDirection=desc&filterField=role&filterOperator=ne&filterValue=user 500 in 499ms ```
Author
Owner

@AnasAitzouinet commented on GitHub (Jan 24, 2025):

If you're still encountering the error:
⨯ TypeError: The "payload" argument must be of type object. Received null,

try adding the following block to the auth.ts file:

onAPIError: {
    onError(e) {
        if (e instanceof Error) {
            console.error(e.stack);
        }
    }
}

While this might not resolve the issue directly, it will help you understand what's causing the error.

<!-- gh-comment-id:2613170787 --> @AnasAitzouinet commented on GitHub (Jan 24, 2025): If you're still encountering the error: `⨯ TypeError: The "payload" argument must be of type object. Received null`, try adding the following block to the `auth.ts` file: ```typescript onAPIError: { onError(e) { if (e instanceof Error) { console.error(e.stack); } } } ``` While this might not resolve the issue directly, it will help you understand what's causing the error.
Author
Owner

@dpflucas commented on GitHub (Jan 28, 2025):

Tried again and now I don't get any error, but when using ne as the filterOperator I don't get any results

<!-- gh-comment-id:2618780236 --> @dpflucas commented on GitHub (Jan 28, 2025): Tried again and now I don't get any error, but when using `ne` as the `filterOperator` I don't get any results
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25735