additional fields not passed to db hooks #2632

Closed
opened 2026-03-13 10:09:37 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @gloced on GitHub (Dec 30, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

my betterAuthOptions contains additional field for the user, namely firstName and lastName. Since "name" is a core field of betterAuth, using a before create db hook I'd like to concat first and last name to create a name. however, firstName and lastName are striped from the user object

Current vs. Expected behavior

POST http://localhost:3000/api/auth/admin/create-user
{"email":"some@email.me","password":"somePassowrd","lastName":"lastName","firstName":"fistName","role":"user","name":"firstName lastName"}

databaseHooks: {
    user: {
      update: {
        before: async (user, ctx) => {
        ....

the user object only contains:

user {
  "createdAt": "2025-12-30T11:16:16.365Z",
  "updatedAt": "2025-12-30T11:16:16.365Z",
  "email": "some@email.me",
  "name": "fistName lastName",
  "role": "user",
  "normalizedEmail": "some@email.me"
}

        }
      },

What version of Better Auth are you using?

1.4.10-beta.1

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041",
    "release": "25.1.0",
    "cpuCount": 14,
    "cpuModel": "Apple M4 Pro",
    "totalMemory": "64.00 GB",
    "freeMemory": "5.11 GB"
  },
  "node": {
    "version": "v24.2.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.3.0"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "15.4.10"
    },
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.10-beta.1",
    "config": null
  }
}

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

Backend, Client

Auth config (if applicable)

export const betterAuthOptions = {
...
user: {
    additionalFields: {
      firstName: {
        returned: true,
        type: 'string',
        required: true,
        input: true
      },
      lastName: {
        returned: true,
        type: 'string',
        required: true,
        input: true
      },
      name: {
        returned: false,
        type: 'string',
        required: false,
        input: false
      },
    },
...
 databaseHooks: {
    user: {
      update: {
        before: async (user, ctx) => {
          return updateNameOfUser(user, ctx)
        }
      },
      create: {
        before: async (user, ctx) => {
          return updateNameOfUser(user, ctx)
        }
      }
    }
  }
} satisfies BetterAuthOptions

Additional context

also the authClient client.admin.createUser does not know the types lastName and firstName

auth client:

import type {betterAuthOptions as auth} from '@/lib/auth/options'

...
plugins: [
...
inferAdditionalFields()
],
...

Originally created by @gloced on GitHub (Dec 30, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce my betterAuthOptions contains additional field for the user, namely firstName and lastName. Since "name" is a core field of betterAuth, using a before create db hook I'd like to concat first and last name to create a name. however, firstName and lastName are striped from the user object ### Current vs. Expected behavior POST http://localhost:3000/api/auth/admin/create-user `{"email":"some@email.me","password":"somePassowrd","lastName":"lastName","firstName":"fistName","role":"user","name":"firstName lastName"}` ``` databaseHooks: { user: { update: { before: async (user, ctx) => { .... ``` the user object only contains: ``` user { "createdAt": "2025-12-30T11:16:16.365Z", "updatedAt": "2025-12-30T11:16:16.365Z", "email": "some@email.me", "name": "fistName lastName", "role": "user", "normalizedEmail": "some@email.me" } } }, ``` ### What version of Better Auth are you using? 1.4.10-beta.1 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041", "release": "25.1.0", "cpuCount": 14, "cpuModel": "Apple M4 Pro", "totalMemory": "64.00 GB", "freeMemory": "5.11 GB" }, "node": { "version": "v24.2.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.3.0" }, "frameworks": [ { "name": "next", "version": "15.4.10" }, { "name": "react", "version": "19.2.3" } ], "databases": null, "betterAuth": { "version": "^1.4.10-beta.1", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript export const betterAuthOptions = { ... user: { additionalFields: { firstName: { returned: true, type: 'string', required: true, input: true }, lastName: { returned: true, type: 'string', required: true, input: true }, name: { returned: false, type: 'string', required: false, input: false }, }, ... databaseHooks: { user: { update: { before: async (user, ctx) => { return updateNameOfUser(user, ctx) } }, create: { before: async (user, ctx) => { return updateNameOfUser(user, ctx) } } } } } satisfies BetterAuthOptions ``` ### Additional context also the authClient client.admin.createUser does not know the types lastName and firstName auth client: import type {betterAuthOptions as auth} from '@/lib/auth/options' ... plugins: [ ... inferAdditionalFields<typeof auth>() ], ...
GiteaMirror added the enhancement label 2026-03-13 10:09:37 -05:00
Author
Owner

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

It seems like you're having issues with additional fields not being passed to the database hooks in your Better Auth implementation. This is a common challenge, as there have been reported scenarios where additional fields like firstName and lastName are not returned in the user object during database operations.

From your provided code, it looks like you are correctly accessing the additional fields in your betterAuthOptions. However, make sure that these fields are defined in your database model and that you are properly handling them in your hooks.

Here are a few steps you can take to troubleshoot:

  1. Ensure Fields Are Defined: Double-check that firstName and lastName are included in your additionalFields within the user object configuration.

  2. Modify Before Hooks: Update your databaseHooks to ensure that the final object returned from the before hook contains all necessary fields. For example, make sure to explicitly return the modified user object including firstName, lastName, or whatever you need to save.

    Example:

    create: {
      before: async (user, ctx) => {
        return {
          ...user,
          name: `${user.firstName} ${user.lastName}`,
        };
      },
    }
    
  3. Check Client-Side Type Inference: Ensure that your client is properly inferring the additional fields. You can use the inferAdditionalFields plugin when creating your auth client. If the additional fields are not included in the inferred types, they won't be recognized by the client side.

  4. Review Database Integration: Consider whether the database layer is correctly configured to accept and return these additional fields.

It may also be worth mentioning that there is an open enhancement request regarding the support for additional fields in databaseHooks, which indicates some areas where improvements are being made in Better Auth [10].

If these suggestions do not resolve your issues, please feel free to tag @bekacru and @ping__ for more specialized assistance!

What specific integration issue are you encountering, or do you have other questions about this setup?

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 (Dec 30, 2025): It seems like you're having issues with additional fields not being passed to the database hooks in your Better Auth implementation. This is a common challenge, as there have been reported scenarios where additional fields like `firstName` and `lastName` are not returned in the user object during database operations. From your provided code, it looks like you are correctly accessing the additional fields in your `betterAuthOptions`. However, make sure that these fields are defined in your database model and that you are properly handling them in your hooks. Here are a few steps you can take to troubleshoot: 1. **Ensure Fields Are Defined**: Double-check that `firstName` and `lastName` are included in your `additionalFields` within the user object configuration. 2. **Modify Before Hooks**: Update your `databaseHooks` to ensure that the final object returned from the `before` hook contains all necessary fields. For example, make sure to explicitly return the modified user object including `firstName`, `lastName`, or whatever you need to save. Example: ```typescript create: { before: async (user, ctx) => { return { ...user, name: `${user.firstName} ${user.lastName}`, }; }, } ``` 3. **Check Client-Side Type Inference**: Ensure that your client is properly inferring the additional fields. You can use the `inferAdditionalFields` plugin when creating your auth client. If the additional fields are not included in the inferred types, they won't be recognized by the client side. 4. **Review Database Integration**: Consider whether the database layer is correctly configured to accept and return these additional fields. It may also be worth mentioning that there is an open enhancement request regarding the support for additional fields in `databaseHooks`, which indicates some areas where improvements are being made in Better Auth [[10]](https://github.com/better-auth/better-auth/issues/2410). If these suggestions do not resolve your issues, please feel free to tag @bekacru and @ping__ for more specialized assistance! What specific integration issue are you encountering, or do you have other questions about this setup? _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2632