additionalFields should support custom TypeScript types #2088

Closed
opened 2026-03-13 09:26:07 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @anthonyma94 on GitHub (Oct 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

Currently, additionalFields in the users section only support primitive types. Having it support TypeScript types would be tremendously helpful. For example:

import { betterAuth } from "better-auth";
export const auth = betterAuth({
	user: {
		additionalFields: {
			customField: {
				type: "string",
                typescriptType: $type<CustomStringType>(), // $type() would be a utility function provided by better-auth
			}
		},
	},
})

Alternatively, updating validator to support Standard Schema would be great as well, since it supports type inference via its validators.

Describe alternatives you've considered

Alternatives are listed above.

Additional context

No response

Originally created by @anthonyma94 on GitHub (Oct 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like Currently, `additionalFields` in the users section only support primitive types. Having it support TypeScript types would be tremendously helpful. For example: ```ts import { betterAuth } from "better-auth"; export const auth = betterAuth({ user: { additionalFields: { customField: { type: "string", typescriptType: $type<CustomStringType>(), // $type() would be a utility function provided by better-auth } }, }, }) ``` Alternatively, updating `validator` to support [Standard Schema](https://github.com/standard-schema/standard-schema) would be great as well, since it supports type inference via its validators. ### Describe alternatives you've considered Alternatives are listed above. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:26:07 -05:00
Author
Owner

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

For enum types you can pass a string of arrays

const auth = betterAuth({
	user: {
		additionalFields: {
			newField: {
				type: ["value1", "value2"],
			},
		},
	},
})
@Bekacru commented on GitHub (Oct 7, 2025): For enum types you can pass a string of arrays ```ts const auth = betterAuth({ user: { additionalFields: { newField: { type: ["value1", "value2"], }, }, }, }) ```
Author
Owner

@kno-raziel commented on GitHub (Nov 17, 2025):

hi @Bekacru are validators suported?

Got this hint in my editor

Image

But for some reason is not working, at least not in my current integration with Convex

Found this in the source code here, but cant figure it out if this is working ...

a475b8f8f3/packages/core/src/db/type.ts (L109-L114)

I would appreaciate your help.

@kno-raziel commented on GitHub (Nov 17, 2025): hi @Bekacru are validators suported? Got this hint in my editor <img width="393" height="414" alt="Image" src="https://github.com/user-attachments/assets/a1ef12bb-1132-42d2-9aa0-8cc4ace1cc10" /> But for some reason is not working, at least not in my current integration with Convex Found this in the source code here, but cant figure it out if this is working ... https://github.com/better-auth/better-auth/blob/a475b8f8f39b7cced5f4abfc0bb4ea4671567aa5/packages/core/src/db/type.ts#L109-L114 I would appreaciate your help.
Author
Owner

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

while this works for single string, if i want to add and enum array field
its not accepting the type using 'create:user","update:user"

is there a way to do the type for example as ("create:user"|"update:user")[]?
i think it should infer validators.output if its present but its not doing that currently

@neronim1141 commented on GitHub (Nov 27, 2025): while this works for single string, if i want to add and enum array field its not accepting the type using [['create:user","update:user"]] is there a way to do the type for example as `("create:user"|"update:user")[]`? i think it should infer validators.output if its present but its not doing that currently
Author
Owner

@dosubot[bot] commented on GitHub (Feb 26, 2026):

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

Issue Summary:

  • You requested support for custom TypeScript types in the users section's additionalFields to improve type safety and flexibility.
  • Workarounds like using string arrays for enum types were shared by others, but these are limited.
  • Discussions revealed challenges with validators and complex enum array typings not being properly inferred.
  • The issue highlights current limitations in type inference and validation for advanced TypeScript types in additionalFields.
  • No resolution has been reached yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, I will automatically close this issue.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 26, 2026): Hi, @anthonyma94. 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 requested support for custom TypeScript types in the users section's additionalFields to improve type safety and flexibility. - Workarounds like using string arrays for enum types were shared by others, but these are limited. - Discussions revealed challenges with validators and complex enum array typings not being properly inferred. - The issue highlights current limitations in type inference and validation for advanced TypeScript types in additionalFields. - No resolution has been reached yet. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I don’t hear back within 7 days, I will automatically close this issue. Thanks 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#2088