Types of additionalFields not inferred correctly when customSession plugin is used #556

Closed
opened 2026-03-13 07:52:45 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @zeutyx on GitHub (Jan 11, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure an auth instance with some additionalFields and the plugin customSession.

Current vs. Expected behavior

The types of the fields specified in the additionalFields should be included in callback function of customSession, but they aren't. Additionally, they are also missing from the returned data of auth.api.getSession. There might be other places where the types are missing with those combinations, but these are the ones I've encountered so far.

const auth = betterAuth({
  user: {
    additionalFields: {
      customerId: {
        type: "string",
        required: false,
        input: false,
      },
    },
  },
  plugins: [
    customSession(async ({ user, session }) => {
      // type of `user` doesn't include customerId
      return { user, session };
    }),
  ],
});

const data = auth.api.getSession({
  headers: {} as Headers,
});
// type of `data.user` doesn't include customerId

interface Test {
  user: import("better-auth").User
  // type of `user` doesn't include customerId
}

What version of Better Auth are you using?

1.1.11

Provide environment information

- OS: Windows 11

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

Backend, Types

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  user: {
    additionalFields: {
      customerId: {
        type: "string",
        required: false,
        input: false,
      },
    },
  },
  plugins: [
    customSession(async ({ user, session }) => {
      // type of `user` doesn't include customerId
      return { user, session };
    }),
  ],
});

Additional context

Note that this issue only affects the types, the values of the additional fields themselves are returned properly.

Originally created by @zeutyx on GitHub (Jan 11, 2025). ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce 1. Configure an auth instance with some `additionalFields` and the plugin `customSession`. ### Current vs. Expected behavior The types of the fields specified in the `additionalFields` should be included in callback function of `customSession`, but they aren't. Additionally, they are also missing from the returned data of `auth.api.getSession`. There might be other places where the types are missing with those combinations, but these are the ones I've encountered so far. ```typescript const auth = betterAuth({ user: { additionalFields: { customerId: { type: "string", required: false, input: false, }, }, }, plugins: [ customSession(async ({ user, session }) => { // type of `user` doesn't include customerId return { user, session }; }), ], }); const data = auth.api.getSession({ headers: {} as Headers, }); // type of `data.user` doesn't include customerId interface Test { user: import("better-auth").User // type of `user` doesn't include customerId } ``` ### What version of Better Auth are you using? 1.1.11 ### Provide environment information ```bash - OS: Windows 11 ``` ### Which area(s) are affected? (Select all that apply) Backend, Types ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ user: { additionalFields: { customerId: { type: "string", required: false, input: false, }, }, }, plugins: [ customSession(async ({ user, session }) => { // type of `user` doesn't include customerId return { user, session }; }), ], }); ``` ### Additional context Note that this issue only affects the types, the values of the additional fields themselves are returned properly.
GiteaMirror added the bug label 2026-03-13 07:52:46 -05:00
Author
Owner

@Bekacru commented on GitHub (Feb 2, 2025):

see the some caveats section here:

https://www.better-auth.com/docs/concepts/session-management#customizing-session-response

@Bekacru commented on GitHub (Feb 2, 2025): see the some caveats section here: https://www.better-auth.com/docs/concepts/session-management#customizing-session-response
Author
Owner

@dosubot[bot] commented on GitHub (Jun 14, 2025):

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

Issue Summary:

  • The issue involves the customSession plugin in Better Auth, where additionalFields types are not correctly inferred.
  • This affects backend operations and types in version 1.1.11 on Windows 11.
  • @Bekacru suggested reviewing the "some caveats" section in the Better Auth documentation.
  • @showduhtung reacted positively to this suggestion, indicating it may have resolved the issue.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no further updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 14, 2025): Hi, @aymanoid. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - The issue involves the `customSession` plugin in Better Auth, where `additionalFields` types are not correctly inferred. - This affects backend operations and types in version 1.1.11 on Windows 11. - @Bekacru suggested reviewing the "some caveats" section in the Better Auth documentation. - @showduhtung reacted positively to this suggestion, indicating it may have resolved the issue. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no further updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@najibghadri commented on GitHub (Aug 8, 2025):

This should be reopened

@najibghadri commented on GitHub (Aug 8, 2025): This should be reopened
Author
Owner

@SapphoSys commented on GitHub (Aug 15, 2025):

+1. Please reopen the issue. Even when using customSession, getSession does NOT return the additional fields.

@SapphoSys commented on GitHub (Aug 15, 2025): +1. Please reopen the issue. Even when using `customSession`, `getSession` does NOT return the additional fields.
Author
Owner

@at0mweb commented on GitHub (Mar 12, 2026):

+1

@at0mweb commented on GitHub (Mar 12, 2026): +1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#556