[GH-ISSUE #194] CLI Schema generate generates buggy prisma.schema file and doesn't respect the types specified in auth file. #25491

Closed
opened 2026-04-17 15:44:34 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @bhaveshxrawat on GitHub (Oct 16, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/194

Describe the bug
Having my auth set up and extending the core schema in the auth.ts file. Upon generating the schema using npx @better-auth/cli@latest generate, the schema is generated for sure. But, the schema type in the schema.prisma file doesn't matches type in the auth file. Adding to that, the CLI also gets the relation between models wrong. Relation between User, Session, and Account.

To Reproduce
Steps to reproduce the behavior:

  1. Go to auth.ts file and extending the core schema using this https://www.better-auth.com/docs/concepts/database#extending-core-schema
  2. Save the file.
  3. Run the command npx @better-auth/cli@latest generate
  4. Press Y and then enter upon being asked, "Do you want to generate schema.prisma".
  5. The file will be generated with relation syntax issue and field types.
//auth.ts

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql", // or "mysql", "postgresql", ...etc
  }),
  user: {
    additionalFields: {
      education_level: {
        type: "string",
        required: false,
        defaultValue: null,
        input: true,
      },
      learning_style: {
        type: "string[]",
        required: false,
        defaultValue: null,
        input: true,
      },
      explanation_type: {
        type: "string[]",
        required: false,
        defaultValue: null,
        input: true,
      },
      hobbies: {
        type: "string[]",
        required: false,
        defaultValue: null,
        input: true,
      },
    },
  },
});

Screenshots
The generated schema file
image
Notice how the field type are all string despite explicitly specifying the fields as array of strings.

Desktop (please complete the following information):

  • OS: [Windows]
Originally created by @bhaveshxrawat on GitHub (Oct 16, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/194 **Describe the bug** Having my auth set up and extending the core schema in the auth.ts file. Upon generating the schema using `npx @better-auth/cli@latest generate`, the schema is generated for sure. But, the schema type in the schema.prisma file doesn't matches type in the auth file. Adding to that, the CLI also gets the relation between models wrong. Relation between User, Session, and Account. **To Reproduce** Steps to reproduce the behavior: 1. Go to auth.ts file and extending the core schema using this https://www.better-auth.com/docs/concepts/database#extending-core-schema 2. Save the file. 3. Run the command `npx @better-auth/cli@latest generate` 4. Press Y and then enter upon being asked, "Do you want to generate schema.prisma". 5. The file will be generated with relation syntax issue and field types. ``` //auth.ts export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", // or "mysql", "postgresql", ...etc }), user: { additionalFields: { education_level: { type: "string", required: false, defaultValue: null, input: true, }, learning_style: { type: "string[]", required: false, defaultValue: null, input: true, }, explanation_type: { type: "string[]", required: false, defaultValue: null, input: true, }, hobbies: { type: "string[]", required: false, defaultValue: null, input: true, }, }, }, }); ``` **Screenshots** The generated schema file ![image](https://github.com/user-attachments/assets/62de7fff-40af-4dcf-9ce1-e65310d4ebf4) Notice how the field type are all string despite explicitly specifying the fields as array of strings. **Desktop (please complete the following information):** - OS: [Windows]
GiteaMirror added the locked label 2026-04-17 15:44:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25491