[GH-ISSUE #6318] Admin plugin getUser endpoint does not return typed additional fields #19113

Open
opened 2026-04-15 17:54:10 -05:00 by GiteaMirror · 13 comments
Owner

Originally created by @ezeparziale on GitHub (Nov 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6318

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Hi!
I'm using the admin plugin and noticed that the getUser endpoint is not returning the full typing for custom/additional user fields.

import { headers } from "next/headers"
import { auth } from "@/lib/auth/auth"

export async function getUser(userId: string) {
  try {
    const user = await auth.api.getUser({
      query: { id: userId },
      headers: await headers(),
    })
    return user
  } catch (error) {
    console.error(`User not found: ${userId}`, error)
    return null
  }
}

Actual typing returned

The response is typed only as:

const user: {
  id: string
  createdAt: Date
  updatedAt: Date
  email: string
  emailVerified: boolean
  name: string
  image?: string | null | undefined
}

Current vs. Expected behavior

auth.api.getUser should return the full inferred type of the User model, including any added fields defined in the Better Auth configuration.

What version of Better Auth are you using?

1.4.2

System info

{
  "system": {
    "platform": "darwin",
    "arch": "x64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:26:51 PDT 2025; root:xnu-12377.41.6~2/RELEASE_X86_64",
    "release": "25.1.0",
    "cpuCount": 12,
    "cpuModel": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.04 GB"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.3"
    },
    {
      "name": "react",
      "version": "19.2.0"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "6.18.0"
    }
  ],
  "betterAuth": {
    "version": "1.4.2",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
  appName: "Template",
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
  user: {
    deleteUser: {
      enabled: true,
    },
    additionalFields: {
      bio: {
        type: "string",
        required: false,
        fieldName: "bio",
      },
    },
  },
...

Additional context

No response

Originally created by @ezeparziale on GitHub (Nov 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6318 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Hi! I'm using the admin plugin and noticed that the getUser endpoint is not returning the full typing for custom/additional user fields. ```typescript import { headers } from "next/headers" import { auth } from "@/lib/auth/auth" export async function getUser(userId: string) { try { const user = await auth.api.getUser({ query: { id: userId }, headers: await headers(), }) return user } catch (error) { console.error(`User not found: ${userId}`, error) return null } } ``` ### Actual typing returned The response is typed only as: ```tyepscript const user: { id: string createdAt: Date updatedAt: Date email: string emailVerified: boolean name: string image?: string | null | undefined } ``` ### Current vs. Expected behavior auth.api.getUser should return the full inferred type of the User model, including any added fields defined in the Better Auth configuration. ### What version of Better Auth are you using? 1.4.2 ### System info ```bash { "system": { "platform": "darwin", "arch": "x64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:26:51 PDT 2025; root:xnu-12377.41.6~2/RELEASE_X86_64", "release": "25.1.0", "cpuCount": 12, "cpuModel": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz", "totalMemory": "16.00 GB", "freeMemory": "0.04 GB" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "16.0.3" }, { "name": "react", "version": "19.2.0" } ], "databases": [ { "name": "@prisma/client", "version": "6.18.0" } ], "betterAuth": { "version": "1.4.2", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ appName: "Template", database: prismaAdapter(db, { provider: "postgresql", }), user: { deleteUser: { enabled: true, }, additionalFields: { bio: { type: "string", required: false, fieldName: "bio", }, }, }, ... ``` ### Additional context _No response_
GiteaMirror added the corebugorganization labels 2026-04-15 17:54:10 -05:00
Author
Owner

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

Thanks for raising this! It appears that when using the admin plugin, the getUser endpoint currently returns only the base user fields and does not include the custom additional fields from your configuration. This is a known issue—our team has received similar reports about extended schema fields not being inferred (i.e., the types aren’t fully reflecting your extra fields) [1]. As a workaround, you can manually extend or assert the User type locally until we push a fix. Are you open to trying a temporary manual type extension, or would you like to share more details so we can further investigate? Tag @bekacru and @ping__ if you need deeper assistance. Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3578027917 --> @better-auth-agent[bot] commented on GitHub (Nov 25, 2025): Thanks for raising this! It appears that when using the admin plugin, the getUser endpoint currently returns only the base user fields and does not include the custom additional fields from your configuration. This is a known issue—our team has received similar reports about extended schema fields not being inferred (i.e., the types aren’t fully reflecting your extra fields) [[1]](https://github.com/better-auth/better-auth/issues/4125). As a workaround, you can manually extend or assert the User type locally until we push a fix. Are you open to trying a temporary manual type extension, or would you like to share more details so we can further investigate? Tag @bekacru and @ping__ if you need deeper assistance. 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

@rovertrack commented on GitHub (Nov 26, 2025):

@better-auth-agent the additional fields are in DB , but are not returning?

<!-- gh-comment-id:3582035801 --> @rovertrack commented on GitHub (Nov 26, 2025): @better-auth-agent the additional fields are in DB , but are not returning?
Author
Owner

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

It looks like the additional custom fields (like your “bio” field) are correctly stored in your database but aren’t being type‐inferred or returned in the response from the getUser endpoint. This behavior has been observed before: the system sometimes only returns the base user type while the extended schema fields aren’t merged into the returned type. One troubleshooting step is to check that you’re running the most up-to-date version of the admin plugin, since improvements and fixes for type inference have been made in prior releases. You might also try regenerating your TypeScript types or verifying that your auth configuration is properly updated to include the additional fields in all endpoints.

Have you seen similar issues when using other endpoints (for example, during sign-up) or only with the admin plugin’s getUser? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3582037112 --> @better-auth-agent[bot] commented on GitHub (Nov 26, 2025): It looks like the additional custom fields (like your “bio” field) are correctly stored in your database but aren’t being type‐inferred or returned in the response from the getUser endpoint. This behavior has been observed before: the system sometimes only returns the base user type while the extended schema fields aren’t merged into the returned type. One troubleshooting step is to check that you’re running the most up-to-date version of the admin plugin, since improvements and fixes for type inference have been made in prior releases. You might also try regenerating your TypeScript types or verifying that your auth configuration is properly updated to include the additional fields in all endpoints. Have you seen similar issues when using other endpoints (for example, during sign-up) or only with the admin plugin’s getUser? 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

@douglasndm commented on GitHub (Nov 26, 2025):

I have the same issue. The additional data is on DB, and it is returned as well, but Typescript still does not recognize additional data

<!-- gh-comment-id:3582924549 --> @douglasndm commented on GitHub (Nov 26, 2025): I have the same issue. The additional data is on DB, and it is returned as well, but Typescript still does not recognize additional data
Author
Owner

@Ridhim-RR commented on GitHub (Nov 27, 2025):

Working on it

<!-- gh-comment-id:3584701600 --> @Ridhim-RR commented on GitHub (Nov 27, 2025): Working on it
Author
Owner

@ezeparziale commented on GitHub (Nov 27, 2025):

I realized that in updateUser the returned data also has the same issue with the typing.

<!-- gh-comment-id:3585668272 --> @ezeparziale commented on GitHub (Nov 27, 2025): I realized that in updateUser the returned data also has the same issue with the typing.
Author
Owner

@Ridhim-RR commented on GitHub (Nov 27, 2025):

checking

<!-- gh-comment-id:3586114370 --> @Ridhim-RR commented on GitHub (Nov 27, 2025): checking
Author
Owner

@Ridhim-RR commented on GitHub (Nov 27, 2025):

@ezeparziale There was only one change which needs to be done for the updateUser , I have implemented it .So now the he server-side is fixed for both of these functions

<!-- gh-comment-id:3586348256 --> @Ridhim-RR commented on GitHub (Nov 27, 2025): @ezeparziale There was only one change which needs to be done for the updateUser , I have implemented it .So now the he server-side is fixed for both of these functions
Author
Owner

@Ridhim-RR commented on GitHub (Nov 27, 2025):

@better-auth-agent will this work
import { inferAdditionalFields } from "better-auth/plugins/additional-fields";

const client = createAuthClient({
plugins: [
adminClient(),
inferAdditionalFields() // Pass your auth instance
],
baseURL: "http://localhost:3000",
});

// Now TypeScript knows about bio!
const user = await client.admin.getUser({ query: { id: userId } });
user.bio // TypeScript recognizes bio

<!-- gh-comment-id:3586355386 --> @Ridhim-RR commented on GitHub (Nov 27, 2025): @better-auth-agent will this work import { inferAdditionalFields } from "better-auth/plugins/additional-fields"; const client = createAuthClient({ plugins: [ adminClient(), inferAdditionalFields<typeof auth>() // ✅ Pass your auth instance ], baseURL: "http://localhost:3000", }); // Now TypeScript knows about bio! const user = await client.admin.getUser({ query: { id: userId } }); user.bio // ✅ TypeScript recognizes bio
Author
Owner

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

It looks like you’re on the right track by using the inferAdditionalFields plugin with your admin client. By passing your auth instance to inferAdditionalFields when creating the client, TypeScript should now infer any additional fields (like bio) that were added in your auth configuration. Make sure your server-side auth configuration properly defines these additionalFields, as the plugin relies on that configuration for its type inference.

If you’re still experiencing issues, please verify that both your server and client are using matching versions and that the plugin is correctly imported from the right path. Also, check that your setup for the admin client is consistent with how the additional fields are defined in your auth instance.

Has this approach resolved your type inference problem, or do you need further troubleshooting? tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3586357312 --> @better-auth-agent[bot] commented on GitHub (Nov 27, 2025): It looks like you’re on the right track by using the inferAdditionalFields plugin with your admin client. By passing your auth instance to inferAdditionalFields when creating the client, TypeScript should now infer any additional fields (like bio) that were added in your auth configuration. Make sure your server-side auth configuration properly defines these additionalFields, as the plugin relies on that configuration for its type inference. If you’re still experiencing issues, please verify that both your server and client are using matching versions and that the plugin is correctly imported from the right path. Also, check that your setup for the admin client is consistent with how the additional fields are defined in your auth instance. Has this approach resolved your type inference problem, or do you need further troubleshooting? 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

@Ridhim-RR commented on GitHub (Nov 27, 2025):

@ezeparziale give this a try if using admin client. And do let me know if this works.

<!-- gh-comment-id:3586362791 --> @Ridhim-RR commented on GitHub (Nov 27, 2025): @ezeparziale give this a try if using admin client. And do let me know if this works.
Author
Owner

@ezeparziale commented on GitHub (Nov 27, 2025):

@ezeparziale give this a try if using admin client. And do let me know if this works.

Ok! In updateUser I fixed it by adding inferAdditionalFields<typeof auth>() in auth-client.ts.
It now also supports passing additional fields that are mapped in auth.ts.

<!-- gh-comment-id:3586873266 --> @ezeparziale commented on GitHub (Nov 27, 2025): > [@ezeparziale](https://github.com/ezeparziale) give this a try if using admin client. And do let me know if this works. Ok! In `updateUser` I fixed it by adding` inferAdditionalFields<typeof auth>()` in `auth-client.ts`. It now also supports passing additional fields that are mapped in auth.ts.
Author
Owner

@corydeppen commented on GitHub (Feb 4, 2026):

@ezeparziale There was only one change which needs to be done for the updateUser , I have implemented it .So now the he server-side is fixed for both of these functions

@Ridhim-RR Will the fix also address a similar type inference issue when using the adminUpdateUser function from the server?

<!-- gh-comment-id:3849002461 --> @corydeppen commented on GitHub (Feb 4, 2026): > [@ezeparziale](https://github.com/ezeparziale) There was only one change which needs to be done for the updateUser , I have implemented it .So now the he server-side is fixed for both of these functions @Ridhim-RR Will the fix also address a similar type inference issue when using the `adminUpdateUser` function from the server?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19113