[GH-ISSUE #5291] additional field is not working #10204

Closed
opened 2026-04-13 06:11:19 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @xkalf on GitHub (Oct 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5291

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

export const auth = betterAuth({
	user: {
		additionalFields: {
			branchId: {
				type: "string",
			},
			companyId: {
				type: "string",
			},
			kind: {
				type: userKindEnum.enumValues,
				defaultValue: "CUSTOMER",
			},
			employeeId: {
				type: "string",
				required: false,
			},
		},
	},
	database: drizzleAdapter(db, {
		provider: "pg",
	}),
	emailAndPassword: {
		enabled: true,
	},
	plugins: [openAPI(), bearer()],
	basePath: "/api",
	secondaryStorage,
	logger: {
		log(level, ...args) {
			if (
				level === "error" &&
				args[0] === "Error" &&
				args.length === 2 &&
				args[1] instanceof Error &&
				args[1].message === "NOT_FOUND"
			)
				return;
			console[level](...args);
		},
	},
});

when i use

export type User = typeof auth.$Infer.Session.user;

type User = any now also

			const result = await auth.api.signUpEmail({
				body: {
					name: body.name,
					email: body.email,
					password:
						body.password ??
						generator.generate({
							length: 10,
							numbers: true,
						}),
					// @ts-ignore
					companyId,
					// @ts-ignore
					branchId,
					kind: body.kind,
				},
			});

the @ts-ignored fields are getting error type any is not assignable to type 'never'

Current vs. Expected behavior

type User is well typed and can be signup with companyId branchId

What version of Better Auth are you using?

1.3.18

System info

m4 macbook pro

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

Backend, Types

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @xkalf on GitHub (Oct 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5291 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce ```typescript export const auth = betterAuth({ user: { additionalFields: { branchId: { type: "string", }, companyId: { type: "string", }, kind: { type: userKindEnum.enumValues, defaultValue: "CUSTOMER", }, employeeId: { type: "string", required: false, }, }, }, database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, }, plugins: [openAPI(), bearer()], basePath: "/api", secondaryStorage, logger: { log(level, ...args) { if ( level === "error" && args[0] === "Error" && args.length === 2 && args[1] instanceof Error && args[1].message === "NOT_FOUND" ) return; console[level](...args); }, }, }); ``` when i use ``` typescript export type User = typeof auth.$Infer.Session.user; ``` type User = any now also ```typescript const result = await auth.api.signUpEmail({ body: { name: body.name, email: body.email, password: body.password ?? generator.generate({ length: 10, numbers: true, }), // @ts-ignore companyId, // @ts-ignore branchId, kind: body.kind, }, }); ``` the @ts-ignored fields are getting error type any is not assignable to type 'never' ### Current vs. Expected behavior type User is well typed and can be signup with companyId branchId ### What version of Better Auth are you using? 1.3.18 ### System info ```bash m4 macbook pro ``` ### 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({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 06:11:19 -05:00
Author
Owner

@xkalf commented on GitHub (Oct 14, 2025):

Also i updated better-auth version to 1.3.27 still getting same issue

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "ES2022",
    "moduleResolution": "node",
    "types": ["bun-types"],
    "outDir": "./dist/",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "paths": {
      "@/*": ["./src/*"]
    },
    "strictNullChecks": true
  },
  "exclude": ["node_modules", "dist"]
}

here is my tsconfig.json

<!-- gh-comment-id:3399659080 --> @xkalf commented on GitHub (Oct 14, 2025): Also i updated better-auth version to 1.3.27 still getting same issue ```json { "compilerOptions": { "target": "ES2021", "module": "ES2022", "moduleResolution": "node", "types": ["bun-types"], "outDir": "./dist/", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, "paths": { "@/*": ["./src/*"] }, "strictNullChecks": true }, "exclude": ["node_modules", "dist"] } ``` here is my tsconfig.json
Author
Owner

@vnphanquang commented on GitHub (Oct 14, 2025):

There is a PR that I think will fix this but not sure what the blocker is there: https://github.com/better-auth/better-auth/pull/3368

<!-- gh-comment-id:3399869842 --> @vnphanquang commented on GitHub (Oct 14, 2025): There is a PR that I think will fix this but not sure what the blocker is there: https://github.com/better-auth/better-auth/pull/3368
Author
Owner

@SpinBoxx commented on GitHub (Oct 16, 2025):

Just to know if there is a fix because i have the same error

<!-- gh-comment-id:3412807198 --> @SpinBoxx commented on GitHub (Oct 16, 2025): Just to know if there is a fix because i have the same error
Author
Owner

@Bekacru commented on GitHub (Oct 16, 2025):

on signin and signup the base user object is returned. To get the full user object, you need to call getSession or useSession

<!-- gh-comment-id:3413164533 --> @Bekacru commented on GitHub (Oct 16, 2025): on signin and signup the base user object is returned. To get the full user object, you need to call `getSession` or `useSession`
Author
Owner

@xkalf commented on GitHub (Oct 17, 2025):

on signin and signup the base user object is returned. To get the full user object, you need to call getSession or useSession

getSession() also not getting that additional fields

<!-- gh-comment-id:3413711428 --> @xkalf commented on GitHub (Oct 17, 2025): > on signin and signup the base user object is returned. To get the full user object, you need to call `getSession` or `useSession` getSession() also not getting that additional fields
Author
Owner

@Bekacru commented on GitHub (Oct 17, 2025):

probably type: userKindEnum.enumValues is the reason. You cant provide enum values as a type

<!-- gh-comment-id:3413772205 --> @Bekacru commented on GitHub (Oct 17, 2025): probably `type: userKindEnum.enumValues` is the reason. You cant provide enum values as a type
Author
Owner

@tvanbeek commented on GitHub (Oct 17, 2025):

Same issue here, take this auth.ts:

// auth.ts
import { betterAuth } from "better-auth";

export const auth = betterAuth({
  user: {
    additionalFields: {
      foo: {
        type: "string",
      },
    },
  },
  ...
});

export type User = typeof auth.$Infer.Session.user; // <-- lets inspect this

Lets take a closer look at what the User type looks like for different versions of the library:

// better-auth@1.3.23
type User = {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    email: string;
    emailVerified: boolean;
    name: string;
    image?: string | null | undefined;
    foo: string; // <-- still here
}

// better-auth@1.3.24
// better-auth@1.3.25
// better-auth@1.3.26
type User = {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    email: string;
    emailVerified: boolean;
    name: string;
    image?: string | null | undefined;
}

// better-auth@1.3.27
type User = any

There is a similar but slightly different issue using getSession(). In my example I use NextJS15 App Router but I assume this is irrelevant. Lets inspect using the same auth.ts example as above:

// /src/app/somepage/page.tsx
import { headers } from "next/headers";

import { auth } from "@/lib/auth"; // <-- this is the export from auth.ts

const Page = async () => {
  const session = await auth.api.getSession({
    headers: await headers(),
  });

  const user = session?.user; // <-- we are interested in the user object

  ...
};

export default Page;

So now we can take a closer look at the user object:

// better-auth@1.3.23
const user: {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    email: string;
    emailVerified: boolean;
    name: string;
    image?: string | null | undefined;
    foo: string; // <-- still here
} | undefined

// better-auth@1.3.24
// better-auth@1.3.25
// better-auth@1.3.26
// better-auth@1.3.27 <-- this is different compared to the previous example where for version 1.3.27 the type was `any`
const user: {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    email: string;
    emailVerified: boolean;
    name: string;
    image?: string | null | undefined;
} | undefined
<!-- gh-comment-id:3414706745 --> @tvanbeek commented on GitHub (Oct 17, 2025): Same issue here, take this auth.ts: ```ts // auth.ts import { betterAuth } from "better-auth"; export const auth = betterAuth({ user: { additionalFields: { foo: { type: "string", }, }, }, ... }); export type User = typeof auth.$Infer.Session.user; // <-- lets inspect this ``` Lets take a closer look at what the `User` type looks like for different versions of the library: ```ts // better-auth@1.3.23 type User = { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; foo: string; // <-- still here } // better-auth@1.3.24 // better-auth@1.3.25 // better-auth@1.3.26 type User = { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; } // better-auth@1.3.27 type User = any ``` There is a similar but slightly different issue using `getSession()`. In my example I use NextJS15 App Router but I assume this is irrelevant. Lets inspect using the same `auth.ts` example as above: ```tsx // /src/app/somepage/page.tsx import { headers } from "next/headers"; import { auth } from "@/lib/auth"; // <-- this is the export from auth.ts const Page = async () => { const session = await auth.api.getSession({ headers: await headers(), }); const user = session?.user; // <-- we are interested in the user object ... }; export default Page; ``` So now we can take a closer look at the `user` object: ```ts // better-auth@1.3.23 const user: { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; foo: string; // <-- still here } | undefined // better-auth@1.3.24 // better-auth@1.3.25 // better-auth@1.3.26 // better-auth@1.3.27 <-- this is different compared to the previous example where for version 1.3.27 the type was `any` const user: { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; } | undefined ```
Author
Owner

@dosubot[bot] commented on GitHub (Jan 16, 2026):

Hi, @xkalf. 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 additionalFields are not properly included in the inferred User type, causing TypeScript errors when passing fields like companyId and branchId.
  • Updating to version 1.3.27 did not resolve the issue; the User type still reverts to any or omits these fields.
  • Contributor vnphanquang referenced PR #3368 as a potential fix.
  • Detailed type inspections by tvanbeek show that versions after 1.3.23 drop the additional fields from the User type.
  • Attempts to retrieve full user data via getSession or useSession also do not include these additional fields as expected.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of better-auth, and if so, you can keep the discussion open by commenting here.
  • Otherwise, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3760783703 --> @dosubot[bot] commented on GitHub (Jan 16, 2026): Hi, @xkalf. 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 `additionalFields` are not properly included in the inferred `User` type, causing TypeScript errors when passing fields like `companyId` and `branchId`. - Updating to version 1.3.27 did not resolve the issue; the `User` type still reverts to `any` or omits these fields. - Contributor vnphanquang referenced PR #3368 as a potential fix. - Detailed type inspections by tvanbeek show that versions after 1.3.23 drop the additional fields from the `User` type. - Attempts to retrieve full user data via `getSession` or `useSession` also do not include these additional fields as expected. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of better-auth, and if so, you can keep the discussion open by commenting here. - Otherwise, I will automatically close this issue in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10204