[GH-ISSUE #2410] additionalFields not supported in databaseHooks #17815

Closed
opened 2026-04-15 16:08:52 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @wadefletch on GitHub (Apr 23, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2410

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

import { BetterAuthOptions, ClientOptions } from "better-auth";
import {
  inferAdditionalFields,
  oneTimeTokenClient,
  organizationClient,
} from "better-auth/client/plugins";
import { oneTimeToken, organization } from "better-auth/plugins";
import emailService from "./email";

export const authConfig = {
  appName: "Additional Fields Example",
  emailAndPassword: {
    enabled: true,
  },
  plugins: [organization(), oneTimeToken()],
  user: {
    additionalFields: {
      firstName: {
        type: "string",
        required: true,
        fieldName: "first_name",
      },
      lastName: {
        type: "string",
        required: true,
        fieldName: "last_name",
      },
    },
  },
  databaseHooks: {
    user: {
      create: {
        after: async (user, ctx) => {
          await emailService.createContact(
            user.email,
            {
               firstName: user.firstName,  // currently has typescript errors
               lastName: user.lastName    // currently has typescript errors
            }
          );
        },
      },
    },
  },
} as const satisfies Omit<BetterAuthOptions, "database">;

Current vs. Expected behavior

I expected the fields established in additionalFields to populate over to the type of the user object in databaseHooks, but they do not.

What version of Better Auth are you using?

1.2.7

Provide environment information

- macOS Sequoia 15.1.1
- Typescript 5.8.2

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

Types

Auth config (if applicable)

See above

Additional context

No response

Originally created by @wadefletch on GitHub (Apr 23, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2410 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```typescript import { BetterAuthOptions, ClientOptions } from "better-auth"; import { inferAdditionalFields, oneTimeTokenClient, organizationClient, } from "better-auth/client/plugins"; import { oneTimeToken, organization } from "better-auth/plugins"; import emailService from "./email"; export const authConfig = { appName: "Additional Fields Example", emailAndPassword: { enabled: true, }, plugins: [organization(), oneTimeToken()], user: { additionalFields: { firstName: { type: "string", required: true, fieldName: "first_name", }, lastName: { type: "string", required: true, fieldName: "last_name", }, }, }, databaseHooks: { user: { create: { after: async (user, ctx) => { await emailService.createContact( user.email, { firstName: user.firstName, // currently has typescript errors lastName: user.lastName // currently has typescript errors } ); }, }, }, }, } as const satisfies Omit<BetterAuthOptions, "database">; ``` ### Current vs. Expected behavior I expected the fields established in additionalFields to populate over to the type of the user object in databaseHooks, but they do not. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - macOS Sequoia 15.1.1 - Typescript 5.8.2 ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) _See above_ ### Additional context _No response_
GiteaMirror added the enhancementlocked labels 2026-04-15 16:08:52 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Apr 25, 2025):

Hey there is a PR open which solves this:
https://github.com/better-auth/better-auth/pull/2158

<!-- gh-comment-id:2830297321 --> @ping-maxwell commented on GitHub (Apr 25, 2025): Hey there is a PR open which solves this: https://github.com/better-auth/better-auth/pull/2158
Author
Owner

@iAmAdheil commented on GitHub (Jun 29, 2025):

Hi!

I had a similar problem.

I added an additional field to my user schema and saving it using signup.email works

I have already added the field inside the inferAdditionalFields as a field for the user schema

but when I try creating a customSession plugin, the additional field on the user is present (I added a console log to check that),
but it throws a type error that that field does not exist. Am I missing something?

Should I open a seperate issue?

<!-- gh-comment-id:3016872814 --> @iAmAdheil commented on GitHub (Jun 29, 2025): Hi! I had a similar problem. I added an additional field to my user schema and saving it using signup.email works I have already added the field inside the inferAdditionalFields as a field for the user schema but when I try creating a customSession plugin, the additional field on the user is present (I added a console log to check that), but it throws a type error that that field does not exist. Am I missing something? Should I open a seperate issue?
Author
Owner

@ping-maxwell commented on GitHub (Jul 1, 2025):

@ibeginnernoob Please open a separate issue.

<!-- gh-comment-id:3021294776 --> @ping-maxwell commented on GitHub (Jul 1, 2025): @ibeginnernoob Please open a separate issue.
Author
Owner

@dosubot[bot] commented on GitHub (Sep 30, 2025):

Hi, @wadefletch. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that in Better Auth v1.2.7, custom fields defined in additionalFields are not reflected in TypeScript types within databaseHooks, causing type errors.
  • A maintainer pointed to an open PR (#2158) that aims to address this type issue.
  • Another user mentioned a related type error with additional fields in a customSession plugin but was advised to open a separate issue.
  • The issue remains unresolved and under discussion.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If no response is received within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3352874719 --> @dosubot[bot] commented on GitHub (Sep 30, 2025): Hi, @wadefletch. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that in Better Auth v1.2.7, custom fields defined in `additionalFields` are not reflected in TypeScript types within `databaseHooks`, causing type errors. - A maintainer pointed to an open PR (#2158) that aims to address this type issue. - Another user mentioned a related type error with additional fields in a customSession plugin but was advised to open a separate issue. - The issue remains unresolved and under discussion. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If no response is received within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Author
Owner

@ping-maxwell commented on GitHub (Oct 1, 2025):

Still relevant.

<!-- gh-comment-id:3356743473 --> @ping-maxwell commented on GitHub (Oct 1, 2025): Still relevant.
Author
Owner

@ataschz commented on GitHub (Oct 9, 2025):

We need this feature and the PR https://github.com/better-auth/better-auth/pull/2158 😭

<!-- gh-comment-id:3384233208 --> @ataschz commented on GitHub (Oct 9, 2025): We need this feature and the PR https://github.com/better-auth/better-auth/pull/2158 😭
Author
Owner

@tzioprodly commented on GitHub (Oct 11, 2025):

still relevant

<!-- gh-comment-id:3392963261 --> @tzioprodly commented on GitHub (Oct 11, 2025): still relevant
Author
Owner

@Frost7994 commented on GitHub (Oct 11, 2025):

Any update?

<!-- gh-comment-id:3393575029 --> @Frost7994 commented on GitHub (Oct 11, 2025): Any update?
Author
Owner

@shaked-frame commented on GitHub (Oct 11, 2025):

still relevant 🙏

<!-- gh-comment-id:3393623492 --> @shaked-frame commented on GitHub (Oct 11, 2025): still relevant 🙏
Author
Owner

@gloced commented on GitHub (Dec 30, 2025):

sill relevant, is there any update?

<!-- gh-comment-id:3699890817 --> @gloced commented on GitHub (Dec 30, 2025): sill relevant, is there any update?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17815