[GH-ISSUE #1993] The pagination query for admin.listUsers did not return total. #8995

Closed
opened 2026-04-13 04:15:01 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Cyanhall on GitHub (Mar 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1993

When the usePlural is set to true:

database: drizzleAdapter(db, {
 provider: 'pg',
 schema,
 usePlural: true
})
const users = await authClient.admin.listUsers({
 query: {
 limit: 10,
 offset: 0
 }
});

The total field is not returned. This may be because the query at internal-adapter.ts is querying the user table instead of the users table.

better-auth version: 1.2.4

Originally created by @Cyanhall on GitHub (Mar 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1993 When the `usePlural` is set to `true`: ```js database: drizzleAdapter(db, { provider: 'pg', schema, usePlural: true }) ``` ```js const users = await authClient.admin.listUsers({ query: { limit: 10, offset: 0 } }); ``` The `total` field is not returned. This may be because the query at [internal-adapter.ts](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/db/internal-adapter.ts#L163) is querying the `user` table instead of the `users` table. better-auth version: 1.2.4
GiteaMirror added the locked label 2026-04-13 04:15:01 -05:00
Author
Owner

@Creaous commented on GitHub (Mar 26, 2025):

I had the same problem, it turns out that the count function (which that total field uses) doesn't work correctly since it's targeting res.count and not res[0].count. I fixed it in #1747, but I ended up closing it in favour of #1737 since that has more improvements. If you don't want to wait for the PR to get merged, I created a patch on my repository here. Put the patch somewhere, you will need to know the path for later. You must go into the node_modules/better-auth directory and run the patch using this command (or the equivalent for your operating system): patch -p1 < "$patch_file" (replace $patch_file with the location of that patch). See the apply.sh script in the same repository if you're confused. This might be a different problem than what I had since I don't have usePlural on but it's worth a try.

<!-- gh-comment-id:2753203826 --> @Creaous commented on GitHub (Mar 26, 2025): I had the same problem, it turns out that the count function (which that total field uses) doesn't work correctly since it's targeting `res.count` and not `res[0].count`. I fixed it in #1747, but I ended up closing it in favour of #1737 since that has more improvements. If you don't want to wait for the PR to get merged, I created a patch on my repository [here](https://github.com/Nexirift/cosmos/blob/main/patches/feat-refactor-database-adapters--1737.patch). Put the patch somewhere, you will need to know the path for later. You must go into the `node_modules/better-auth` directory and run the patch using this command (or the equivalent for your operating system): `patch -p1 < "$patch_file"` (replace `$patch_file` with the location of that patch). See the [apply.sh](https://github.com/Nexirift/cosmos/blob/main/patches/apply.sh) script in the same repository if you're confused. This might be a different problem than what I had since I don't have usePlural on but it's worth a try.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8995