better-auth does not correctly handle enum types for additional user fields. #1762

Closed
opened 2026-03-13 09:01:29 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @coollad49 on GitHub (Aug 23, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Define a Role enum in the prisma/schema.prisma file:

     enum Role {
       ADMIN
       USER
     }
    
  2. In the User model, add a role field of type Role:

     model User {
       // ...
       role Role
     }
    
  3. In the better-auth configuration, add the role as an additional field:

     user: {
       additionalFields: {
         role: {}
       }
     }
    
  4. Try to create a new user with a specific role using the auth.api.signUpEmail function, passing the role as an enum value:

await auth.api.signUpEmail({
    body: {
        name: "Admin User",
        email: "admin@example.com",
        password: "password1234",
        role: Role.ADMIN
   },
});

Current vs. Expected behavior

Description:

When using a Prisma enum type for an additional user field (e.g., role), the better-auth library does not
correctly handle the enum value during user creation. It appears to be converting the enum value to a
string, which then causes a Prisma validation error.

Expected Behavior:

The user should be created with the specified role (ADMIN).

Actual Behavior:

The user creation fails with a PrismaClientValidationError because the library tries to save the role as a string
(e.g., "user") instead of the enum value.

What version of Better Auth are you using?

1.3.6

System info

System:
    OS: Linux 6.15 Fedora Linux 42 (KDE Plasma Desktop Edition)
    CPU: (4) x64 Intel(R) Core(TM) i5-8200Y CPU @ 1.30GHz
    Memory: 1.76 GB / 7.61 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Browsers:
    Chrome: 139.0.7258.66

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

Types, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
user: {
    additionalFields: {
      role: {
        type: "",
        required: false,
      }
    }
  },
});

Additional context

No response

Originally created by @coollad49 on GitHub (Aug 23, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Define a Role enum in the prisma/schema.prisma file: enum Role { ADMIN USER } 2. In the User model, add a role field of type Role: model User { // ... role Role } 3. In the better-auth configuration, add the role as an additional field: user: { additionalFields: { role: {} } } 4. Try to create a new user with a specific role using the auth.api.signUpEmail function, passing the role as an enum value: ``` await auth.api.signUpEmail({ body: { name: "Admin User", email: "admin@example.com", password: "password1234", role: Role.ADMIN }, }); ``` ### Current vs. Expected behavior Description: When using a Prisma enum type for an additional user field (e.g., role), the better-auth library does not correctly handle the enum value during user creation. It appears to be converting the enum value to a string, which then causes a Prisma validation error. Expected Behavior: The user should be created with the specified role (ADMIN). Actual Behavior: The user creation fails with a PrismaClientValidationError because the library tries to save the role as a string (e.g., "user") instead of the enum value. ### What version of Better Auth are you using? 1.3.6 ### System info ```bash System: OS: Linux 6.15 Fedora Linux 42 (KDE Plasma Desktop Edition) CPU: (4) x64 Intel(R) Core(TM) i5-8200Y CPU @ 1.30GHz Memory: 1.76 GB / 7.61 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Browsers: Chrome: 139.0.7258.66 ``` ### Which area(s) are affected? (Select all that apply) Types, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, user: { additionalFields: { role: { type: "", required: false, } } }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:01:29 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 23, 2025):

Better Auth does not currently support Prisma enum types in additionalFields—it treats all such fields as strings, and there’s no built-in mechanism for enum validation or transformation during user creation. This means you’ll encounter Prisma validation errors if you pass enum values that don’t match the expected type or format in your schema. The documentation and recent code changes only show support for primitive types like string, number, and boolean, not enums (docs).

As a workaround, you can manually ensure that the value you pass for the enum field matches the string representation expected by Prisma (e.g., "ADMIN" or "USER"), rather than passing the enum object or value directly. If you want to prevent users from setting the role during signup, set input: false for the field in your config (docs). For more advanced handling, you’d need to add custom validation or mapping logic outside of Better Auth, or propose an enhancement for enum support in future releases.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 23, 2025): <!-- Answer --> Better Auth does not currently support Prisma enum types in `additionalFields`—it treats all such fields as strings, and there’s no built-in mechanism for enum validation or transformation during user creation. This means you’ll encounter Prisma validation errors if you pass enum values that don’t match the expected type or format in your schema. The documentation and recent code changes only show support for primitive types like string, number, and boolean, not enums ([docs](https://better-auth.com/docs/concepts/database)). As a workaround, you can manually ensure that the value you pass for the enum field matches the string representation expected by Prisma (e.g., `"ADMIN"` or `"USER"`), rather than passing the enum object or value directly. If you want to prevent users from setting the role during signup, set `input: false` for the field in your config ([docs](https://better-auth.com/docs/concepts/typescript)). For more advanced handling, you’d need to add custom validation or mapping logic outside of Better Auth, or propose an enhancement for enum support in future releases. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4d8119b7-68db-4540-be66-cf3e1edfd65e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4171)
Author
Owner

@zicjin commented on GitHub (Oct 28, 2025):

@dosu this is not Prisma's enum, this is postgresql's enum type.
I believe support for complete extended field types is a very reasonable requirement.

@zicjin commented on GitHub (Oct 28, 2025): @dosu this is not Prisma's enum, this is postgresql's enum type. I believe support for complete extended field types is a very reasonable requirement.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1762