[GH-ISSUE #5854] Allow zod schema for inferAdditionalFields #10360

Closed
opened 2026-04-13 06:26:57 -05:00 by GiteaMirror · 13 comments
Owner

Originally created by @CamilleHbp on GitHub (Nov 8, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5854

Is this suited for github?

  • Yes, this is suited for github

Currently, we either have to have a monorepo, or type the better-auth function manuallly in all clients.

Describe the solution you'd like

It would be really interesting to allow the use of a zod schema for this function. Better-auth uses zod internally. Is there any reason this is not possible? Thank you! 🙏

Describe alternatives you've considered

Using another library? 🤔

Additional context

No response

Originally created by @CamilleHbp on GitHub (Nov 8, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5854 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, we either have to have a monorepo, or type the better-auth function manuallly in all clients. ### Describe the solution you'd like It would be really interesting to allow the use of a zod schema for this function. Better-auth uses zod internally. Is there any reason this is not possible? Thank you! 🙏 ### Describe alternatives you've considered Using another library? 🤔 ### Additional context _No response_
GiteaMirror added the enhancementlocked labels 2026-04-13 06:26:57 -05:00
Author
Owner

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

Thanks for suggesting the integration of a Zod schema for inferAdditionalFields! Right now, inferAdditionalFields is set up to support primitive types, but there’s been discussion about extending support to custom TypeScript types—which could include Zod schemas—in order to streamline type inference and reduce repetitive manual typing. This aligns with previous conversations on enhancing additionalFields to support custom types, so your idea might fit well with those plans [1].

In the meantime, one workaround is to manually map and validate your additional fields using Zod before passing them to better-auth. It’d be great to know if you have specific use cases that would benefit from native Zod support—this could help us prioritize the enhancement further.

Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3506726898 --> @better-auth-agent[bot] commented on GitHub (Nov 8, 2025): Thanks for suggesting the integration of a Zod schema for inferAdditionalFields! Right now, inferAdditionalFields is set up to support primitive types, but there’s been discussion about extending support to custom TypeScript types—which could include Zod schemas—in order to streamline type inference and reduce repetitive manual typing. This aligns with previous conversations on enhancing additionalFields to support custom types, so your idea might fit well with those plans [[1]](https://www.better-auth.com/docs/reference/contributing). In the meantime, one workaround is to manually map and validate your additional fields using Zod before passing them to better-auth. It’d be great to know if you have specific use cases that would benefit from native Zod support—this could help us prioritize the enhancement further. Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@CamilleHbp commented on GitHub (Nov 8, 2025):

@better-auth-agent In the meantime, one workaround is to manually map and validate your additional fields using Zod before passing them to better-auth. It’d be great to know if you have specific use cases that would benefit from native Zod support—this could help us prioritize the enhancement further. What is the meaning of this in relation to my question? 🤔

<!-- gh-comment-id:3506727959 --> @CamilleHbp commented on GitHub (Nov 8, 2025): @better-auth-agent `In the meantime, one workaround is to manually map and validate your additional fields using Zod before passing them to better-auth. It’d be great to know if you have specific use cases that would benefit from native Zod support—this could help us prioritize the enhancement further.` What is the meaning of this in relation to my question? 🤔
Author
Owner

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

Thanks for asking! The statement means that, at the moment, native support for inferring additional fields directly from a Zod schema isn’t built into better-auth. As a workaround, you can manually validate and map your additional fields using Zod before you pass them into better-auth. This approach lets you continue leveraging Zod’s powerful type inference and validation capabilities while we assess how to best integrate this directly into better-auth in the future. Could you share more about your specific use case or what kind of additional fields you'd want to validate using a Zod schema? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3506728332 --> @better-auth-agent[bot] commented on GitHub (Nov 8, 2025): Thanks for asking! The statement means that, at the moment, native support for inferring additional fields directly from a Zod schema isn’t built into better-auth. As a workaround, you can manually validate and map your additional fields using Zod before you pass them into better-auth. This approach lets you continue leveraging Zod’s powerful type inference and validation capabilities while we assess how to best integrate this directly into better-auth in the future. Could you share more about your specific use case or what kind of additional fields you'd want to validate using a Zod schema? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@CamilleHbp commented on GitHub (Nov 8, 2025):

@better-auth-agent Do you have an example of what you propose? I do not understand.

<!-- gh-comment-id:3506728929 --> @CamilleHbp commented on GitHub (Nov 8, 2025): @better-auth-agent Do you have an example of what you propose? I do not understand.
Author
Owner

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

Here’s one way we’re thinking about it: you could extend the additionalFields configuration so it accepts a Zod schema directly. For example, instead of only specifying a primitive type, you can pass a Zod object definition that defines your custom field. One idea is to allow a configuration like this:

  import { z } from "zod";
  import { betterAuth } from "better-auth";

  const customFieldSchema = z.object({
    customField: z.string(),
  });

  export const auth = betterAuth({
    user: {
      additionalFields: {
        schema: customFieldSchema,
      },
    },
  });

Doing so would leverage the internal use of Zod by better-auth, allowing type inference (using z.infer) directly from your schema. Currently, the system primarily accepts simpler primitive definitions, so this enhancement would streamline type propagation in monorepo scenarios and avoid manual type duplication [1].

Does this example help clarify the proposal? What additional details would you need to move forward? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3506729598 --> @better-auth-agent[bot] commented on GitHub (Nov 8, 2025): Here’s one way we’re thinking about it: you could extend the additionalFields configuration so it accepts a Zod schema directly. For example, instead of only specifying a primitive type, you can pass a Zod object definition that defines your custom field. One idea is to allow a configuration like this:   import { z } from "zod";   import { betterAuth } from "better-auth";   const customFieldSchema = z.object({     customField: z.string(),   });   export const auth = betterAuth({     user: {       additionalFields: {         schema: customFieldSchema,       },     },   }); Doing so would leverage the internal use of Zod by better-auth, allowing type inference (using z.infer) directly from your schema. Currently, the system primarily accepts simpler primitive definitions, so this enhancement would streamline type propagation in monorepo scenarios and avoid manual type duplication [[1]](https://www.better-auth.com/docs/reference/contributing). Does this example help clarify the proposal? What additional details would you need to move forward? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@CamilleHbp commented on GitHub (Nov 8, 2025):

@better-auth-agent What are you on about? You said I could use this as an alternative "in the meantine". What you are proposing is not actually possible in better-auth. You are just describing the feature I want.

<!-- gh-comment-id:3506730779 --> @CamilleHbp commented on GitHub (Nov 8, 2025): @better-auth-agent What are you on about? You said I could use this as an alternative "in the meantine". What you are proposing is not actually possible in better-auth. You are just describing the feature I want.
Author
Owner

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

Thanks for the detailed feedback! I understand you’re looking for built-in support to leverage a Zod schema for inferAdditionalFields. Currently, the implementation only supports primitive types and requires manual TypeScript definitions, and while we do use Zod internally, using it directly for additionalFields isn’t available yet [1].

One next step could be to discuss how we can better integrate Zod’s schema inference to streamline this process. Have you tried any workarounds (like mapping your Zod schema manually) while waiting for full support? Your input is valuable and can help steer future improvements.

tag @better-auth-agent if you would like an answer from the Agent. What additional benefits would you expect from native Zod support in your project?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3506731055 --> @better-auth-agent[bot] commented on GitHub (Nov 8, 2025): Thanks for the detailed feedback! I understand you’re looking for built-in support to leverage a Zod schema for inferAdditionalFields. Currently, the implementation only supports primitive types and requires manual TypeScript definitions, and while we do use Zod internally, using it directly for additionalFields isn’t available yet [[1]](https://github.com/better-auth/better-auth/issues/1373). One next step could be to discuss how we can better integrate Zod’s schema inference to streamline this process. Have you tried any workarounds (like mapping your Zod schema manually) while waiting for full support? Your input is valuable and can help steer future improvements. tag @better-auth-agent if you would like an answer from the Agent. What additional benefits would you expect from native Zod support in your project? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@CamilleHbp commented on GitHub (Nov 8, 2025):

@better-auth-agent I'm actually asking you to show me an example of "mapping your Zod schema manually" possible with the current version of better-auth

<!-- gh-comment-id:3506731618 --> @CamilleHbp commented on GitHub (Nov 8, 2025): @better-auth-agent I'm actually asking you to show me an example of "mapping your Zod schema manually" possible with the current version of better-auth
Author
Owner

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

Below is one approach you can take with the current version. Since Better Auth doesn’t yet auto‐infer additionalFields from a Zod schema, you can define your schema with Zod and then manually map each field to the shape Better Auth expects. For example, if you have a Zod schema like this:

  import { z } from "zod";

  const customSchema = z.object({
   customField: z.string()
  });

You can create a mapping object manually that tells Better Auth the type you expect:

  const additionalFieldsMapping = {
   customField: {
    type: "string",
    // Here you’d indicate the intended TypeScript type—in a real setup you might define a helper
    typescriptType: "string"
   }
  };

Then, when you initialize Better Auth, pass in the mapping:

  import { betterAuth } from "better-auth";

  export const auth = betterAuth({
   user: {
    additionalFields: additionalFieldsMapping,
   },
   // other configuration options…
  });

This lets you use your Zod definition as the source of truth while still manually providing Better Auth the type information it needs. You could also write a small utility that converts your Zod schema definition into the additionalFields mapping format if you have many fields to convert [1].

Does this help, or would you like further clarification on setting up a utility for automating the conversion? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3506731946 --> @better-auth-agent[bot] commented on GitHub (Nov 8, 2025): Below is one approach you can take with the current version. Since Better Auth doesn’t yet auto‐infer additionalFields from a Zod schema, you can define your schema with Zod and then manually map each field to the shape Better Auth expects. For example, if you have a Zod schema like this:   import { z } from "zod";   const customSchema = z.object({    customField: z.string()   }); You can create a mapping object manually that tells Better Auth the type you expect:   const additionalFieldsMapping = {    customField: {     type: "string",     // Here you’d indicate the intended TypeScript type—in a real setup you might define a helper     typescriptType: "string"    }   }; Then, when you initialize Better Auth, pass in the mapping:   import { betterAuth } from "better-auth";   export const auth = betterAuth({    user: {     additionalFields: additionalFieldsMapping,    },    // other configuration options…   }); This lets you use your Zod definition as the source of truth while still manually providing Better Auth the type information it needs. You could also write a small utility that converts your Zod schema definition into the additionalFields mapping format if you have many fields to convert [[1]](https://www.better-auth.com/docs/reference/contributing). Does this help, or would you like further clarification on setting up a utility for automating the conversion? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@GautamBytes commented on GitHub (Nov 9, 2025):

@CamilleHbp working on it!

<!-- gh-comment-id:3507575384 --> @GautamBytes commented on GitHub (Nov 9, 2025): @CamilleHbp working on it!
Author
Owner

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

Hi, @CamilleHbp. 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 native support for using Zod schemas with better-auth's inferAdditionalFields to simplify type management.
  • Currently, better-auth only supports primitive types for additionalFields.
  • The better-auth-agent provided a workaround by manually mapping Zod schemas to the expected format.
  • A maintainer acknowledged the request and is working on native Zod integration.
  • The issue remains unresolved and open for further development.

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, this issue will be automatically closed.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3867477466 --> @dosubot[bot] commented on GitHub (Feb 8, 2026): Hi, @CamilleHbp. 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 native support for using Zod schemas with better-auth's inferAdditionalFields to simplify type management. - Currently, better-auth only supports primitive types for additionalFields. - The better-auth-agent provided a workaround by manually mapping Zod schemas to the expected format. - A maintainer acknowledged the request and is working on native Zod integration. - The issue remains unresolved and open for further development. **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, this issue will be automatically closed. Thank you for your understanding and contribution!
Author
Owner

@CamilleHbp commented on GitHub (Feb 10, 2026):

I don't think this should be closed as long as the feature isn't provided by better-auth. 😊

<!-- gh-comment-id:3878376780 --> @CamilleHbp commented on GitHub (Feb 10, 2026): I don't think this should be closed as long as the feature isn't provided by better-auth. 😊
Author
Owner

@ping-maxwell commented on GitHub (Feb 11, 2026):

Hello, we're moving all feature requests or enhancement issues over to Github Discussions.

I've went ahead and created the discussion here:
https://github.com/better-auth/better-auth/discussions/7909

<!-- gh-comment-id:3882961043 --> @ping-maxwell commented on GitHub (Feb 11, 2026): Hello, we're moving all feature requests or enhancement issues over to Github Discussions. I've went ahead and created the discussion here: https://github.com/better-auth/better-auth/discussions/7909
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10360