listUsers() doesn't include additional fields in the returned users type #2727

Open
opened 2026-03-13 10:15:45 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @mintydev789 on GitHub (Jan 18, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

The auth.api.listUsers() function doesn't include additionalFields in the user return type. I have a configuration like this:

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema,
  }),
  plugins: [
    nextCookies(),
    username({
      maxUsernameLength: 40,
      usernameValidator: (username) => /^[0-9a-zA-Z-_.]*$/.test(username),
    }),
  ],
  user: {
    additionalFields: {
      username: {
        type: "string",
        required: true,
      },
    },
  },
});

I then get the users like this:

const res = await auth.api.listUsers({ headers: await headers() });

Current vs. Expected behavior

The inferred type of the res.users array returned by listUsers() with that setup is simply UserWithRole[], which doesn't include the additional username field. Instead, the type of res.users should match typeof auth.$Infer.Session.user (which I have verified does indeed have the username field.

What version of Better Auth are you using?

1.4.10

System info

.

Which area(s) are affected? (Select all that apply)

Types

Auth config (if applicable)

My full auth config is this (though I shared the relevant parts of it above):


export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      users,
      sessions,
      accounts,
      verifications,
    },
  }),
  plugins: [
    nextCookies(),
    username({
      maxUsernameLength: 40,
      usernameValidator: (username) => /^[0-9a-zA-Z-_.]*$/.test(username),
    }),
    adminPlugin({
      ac,
      roles: { admin, mod, user },
    }),
  ],
  emailAndPassword: {
    enabled: true,
    autoSignIn: false,
    requireEmailVerification: true,
    sendResetPassword: async ({ user, url }) => {
      await sendResetPasswordEmail(user.email, url);
    },
  },
  emailVerification: {
    sendVerificationEmail: async ({ user, url }) => {
      await sendVerificationEmail(user.email, url);
    },
  },
  user: {
    additionalFields: {
      username: {
        type: "string",
        required: true,
      },
    },
    deleteUser: {
      enabled: true,
    },
  },
});

Additional context

No response

Originally created by @mintydev789 on GitHub (Jan 18, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce The `auth.api.listUsers()` function doesn't include `additionalFields` in the user return type. I have a configuration like this: ```ts export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema, }), plugins: [ nextCookies(), username({ maxUsernameLength: 40, usernameValidator: (username) => /^[0-9a-zA-Z-_.]*$/.test(username), }), ], user: { additionalFields: { username: { type: "string", required: true, }, }, }, }); ``` I then get the users like this: ```ts const res = await auth.api.listUsers({ headers: await headers() }); ``` ### Current vs. Expected behavior The inferred type of the `res.users` array returned by `listUsers()` with that setup is simply `UserWithRole[]`, which doesn't include the additional username field. Instead, the type of `res.users` should match `typeof auth.$Infer.Session.user` (which I have verified does indeed have the `username` field. ### What version of Better Auth are you using? 1.4.10 ### System info ```bash . ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript My full auth config is this (though I shared the relevant parts of it above): export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { users, sessions, accounts, verifications, }, }), plugins: [ nextCookies(), username({ maxUsernameLength: 40, usernameValidator: (username) => /^[0-9a-zA-Z-_.]*$/.test(username), }), adminPlugin({ ac, roles: { admin, mod, user }, }), ], emailAndPassword: { enabled: true, autoSignIn: false, requireEmailVerification: true, sendResetPassword: async ({ user, url }) => { await sendResetPasswordEmail(user.email, url); }, }, emailVerification: { sendVerificationEmail: async ({ user, url }) => { await sendVerificationEmail(user.email, url); }, }, user: { additionalFields: { username: { type: "string", required: true, }, }, deleteUser: { enabled: true, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 10:15:45 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 18, 2026):

It looks like you've encountered an issue with the listUsers() function not returning additional fields, specifically the username field that you've added through the configuration. This is a known issue in Better Auth, where additional fields configured for users are not being returned when using the auth.api.listUsers() method, despite being available in the session user type.

The expected behavior would be for the res.users array returned by listUsers() to include those additional fields, but currently, this is not the case. An open issue has been recorded regarding this functionality, highlighting the need for Better Auth to support returning additional fields in user-related API responses [1].

To troubleshoot, ensure that you have the latest version of Better Auth, as updates may address this issue. If you continue to have problems, I recommend tagging @bekacru or @ping__ for more specific guidance from the Better Auth team regarding this issue.

Have you checked if the problem persists after updating to the latest version, or do you need help with anything else regarding your authentication implementation?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 18, 2026): It looks like you've encountered an issue with the `listUsers()` function not returning additional fields, specifically the `username` field that you've added through the configuration. This is a known issue in Better Auth, where additional fields configured for users are not being returned when using the `auth.api.listUsers()` method, despite being available in the session user type. The expected behavior would be for the `res.users` array returned by `listUsers()` to include those additional fields, but currently, this is not the case. An open issue has been recorded regarding this functionality, highlighting the need for Better Auth to support returning additional fields in user-related API responses [[1]](https://github.com/better-auth/better-auth/issues/4870). To troubleshoot, ensure that you have the latest version of Better Auth, as updates may address this issue. If you continue to have problems, I recommend tagging @bekacru or @ping__ for more specific guidance from the Better Auth team regarding this issue. Have you checked if the problem persists after updating to the latest version, or do you need help with anything else regarding your authentication implementation? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- 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

@mintydev789 commented on GitHub (Jan 18, 2026):

It looks like you've encountered an issue with the listUsers() function not returning additional fields, specifically the username field that you've added through the configuration. This is a known issue in Better Auth, where additional fields configured for users are not being returned when using the auth.api.listUsers() method, despite being available in the session user type.

The expected behavior would be for the res.users array returned by listUsers() to include those additional fields, but currently, this is not the case. An open issue has been recorded regarding this functionality, highlighting the need for Better Auth to support returning additional fields in user-related API responses [1].

To troubleshoot, ensure that you have the latest version of Better Auth, as updates may address this issue. If you continue to have problems, I recommend tagging @Bekacru or @ping__ for more specific guidance from the Better Auth team regarding this issue.

Have you checked if the problem persists after updating to the latest version, or do you need help with anything else regarding your authentication implementation?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

That other issue seems to be about the additional fields in runtime, but I'm not having any issues there; it does return the additonal fields as expected. The problem is only with the type. I have updated to version 1.4.15, but the error still persists. @Bekacru the bot said to tag you for assistance.

@mintydev789 commented on GitHub (Jan 18, 2026): > It looks like you've encountered an issue with the `listUsers()` function not returning additional fields, specifically the `username` field that you've added through the configuration. This is a known issue in Better Auth, where additional fields configured for users are not being returned when using the `auth.api.listUsers()` method, despite being available in the session user type. > > The expected behavior would be for the `res.users` array returned by `listUsers()` to include those additional fields, but currently, this is not the case. An open issue has been recorded regarding this functionality, highlighting the need for Better Auth to support returning additional fields in user-related API responses [[1]](https://github.com/better-auth/better-auth/issues/4870). > > To troubleshoot, ensure that you have the latest version of Better Auth, as updates may address this issue. If you continue to have problems, I recommend tagging [@Bekacru](https://github.com/Bekacru) or @ping__ for more specific guidance from the Better Auth team regarding this issue. > > Have you checked if the problem persists after updating to the latest version, or do you need help with anything else regarding your authentication implementation? > > _If you need more help, tag @better-auth-agent in a comment so I can respond._ > > [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://camo.githubusercontent.com/66c06e6468849c4c6af49b6edad983955d87ac1be2d5aac7c0e7b2b4ef684048/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4469616772616d2d3262333133373f7374796c653d666c61742d737175617265)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://camo.githubusercontent.com/786c566c038583b12f1757a3420f88fd59051efdc719b7574438987b0a545b3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6a6f696e2d3538363546323f6c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://discord.gg/better-auth) [![Star](https://camo.githubusercontent.com/45f39e23a829525840ce0c72438ebc5f34db1e9c6614a4c00e6b43506cf033b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461722d3138313731373f6c6f676f3d676974687562266c6f676f436f6c6f723d7768697465267374796c653d666c61742d737175617265)](https://github.com/better-auth/better-auth) That other issue seems to be about the additional fields in runtime, but I'm not having any issues there; it does return the additonal fields as expected. The problem is only with the type. I have updated to version 1.4.15, but the error still persists. @Bekacru the bot said to tag you for assistance.
Author
Owner

@ping-maxwell commented on GitHub (Jan 18, 2026):

Hello, just to give some update/insight, right now plugins can't infer the typings of your auth config (only the opposite way around would work), so since the listUsers endpoint comes from the admin plugin, it isn't able to infer your additional fields defined at the auth-config level.

This is an active issue that has been around for some time that we do intend on resolving, just a matter of finding the right solution for. Not sure when it would be solved but it certainly is on our radar.

@ping-maxwell commented on GitHub (Jan 18, 2026): Hello, just to give some update/insight, right now plugins can't infer the typings of your auth config (only the opposite way around would work), so since the `listUsers` endpoint comes from the admin plugin, it isn't able to infer your additional fields defined at the auth-config level. This is an active issue that has been around for some time that we do intend on resolving, just a matter of finding the right solution for. Not sure when it would be solved but it certainly is on our radar.
Author
Owner

@k2on commented on GitHub (Feb 26, 2026):

I did something like this.

Make a types.d.ts file:

import "better-auth/plugins";
import type { createAuth } from "@/auth/auth-server";
import type { AppRole } from "@/lib/permissions";

type Auth = ReturnType<typeof createAuth>;
type User = Auth["$Infer"]["Session"]["user"];

declare module "better-auth/plugins" {
  type UserWithRole = User;
}
@k2on commented on GitHub (Feb 26, 2026): I did something like this. Make a `types.d.ts` file: ```ts import "better-auth/plugins"; import type { createAuth } from "@/auth/auth-server"; import type { AppRole } from "@/lib/permissions"; type Auth = ReturnType<typeof createAuth>; type User = Auth["$Infer"]["Session"]["user"]; declare module "better-auth/plugins" { type UserWithRole = User; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2727