[GH-ISSUE #1712] Enum support for extending core schema #8881

Closed
opened 2026-04-13 04:07:51 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @bismitpanda on GitHub (Mar 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1712

Is this suited for github?

  • Yes, this is suited for github

I want to limit the user role to specific roles and hence I have an enum in my postgres database corresponding to that. But currently extending the core schema allows for string type as an option for role.

Describe the solution you'd like

I want to have a new field type named enum which should have an additional field called variants which needs to be a const array so that the type union can be inferrer.

Describe alternatives you've considered

checking for validity during runtime.

Additional context

No response

Originally created by @bismitpanda on GitHub (Mar 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1712 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I want to limit the user role to specific roles and hence I have an enum in my postgres database corresponding to that. But currently extending the core schema allows for `string` type as an option for role. ### Describe the solution you'd like I want to have a new field type named `enum` which should have an additional field called `variants` which needs to be a const array so that the type union can be inferrer. ### Describe alternatives you've considered checking for validity during runtime. ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:07:51 -05:00
Author
Owner

@Bekacru commented on GitHub (Mar 6, 2025):

you can pass an array of strings as a type and it'll be inferred as enum.

<!-- gh-comment-id:2704934722 --> @Bekacru commented on GitHub (Mar 6, 2025): you can pass an array of strings as a `type` and it'll be inferred as enum.
Author
Owner

@bismitpanda commented on GitHub (Mar 7, 2025):

Thank you for your response. I was not aware of this. Can you please link the documentation for this? I did not find any information regarding this.

Also this does not create a postgres enum, which was my primary requirement. the type of role is changed into a string union, but the db enum is not created. If it is not possible I will manually change the generated schema.prisma to use the enum instead of String.

<!-- gh-comment-id:2705382922 --> @bismitpanda commented on GitHub (Mar 7, 2025): Thank you for your response. I was not aware of this. Can you please link the documentation for this? I did not find any information regarding this. Also this does not create a postgres enum, which was my primary requirement. the type of role is changed into a string union, but the db enum is not created. If it is not possible I will manually change the generated `schema.prisma` to use the enum instead of `String`.
Author
Owner

@alan345 commented on GitHub (Mar 30, 2025):

Where is the documentation for the array as enum?

<!-- gh-comment-id:2764618873 --> @alan345 commented on GitHub (Mar 30, 2025): Where is the documentation for the array as enum?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8881