bug: defaultValue in additionalFields does not work for drizzle #1213

Closed
opened 2026-03-13 08:28:32 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @eyadfareh on GitHub (May 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. define user and set an additional fields with a default value for drizzle
  2. npx @better-auth/cli generate
  3. the generated schema doesn't put the default value inside a string
  4. it results in invalid drizzle schema
    the schema it produces:
export const user = sqliteTable("user", {
					id: text('id').primaryKey(),
					name: text('name').notNull(),
 email: text('email').notNull().unique(),
 emailVerified: integer('email_verified', { mode: 'boolean' }).$defaultFn(() => false).notNull(),
 image: text('image'),
 createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => /* @__PURE__ */ new Date()).notNull(),
 updatedAt: integer('updated_at', { mode: 'timestamp' }).$defaultFn(() => /* @__PURE__ */ new Date()).notNull(),
 role: text('role').default(user).notNull()
				});

instead of

role: text('role').default("user").notNull()

Current vs. Expected behavior

the default value should be a string, but instead it is an identifier.

What version of Better Auth are you using?

1.2.7

Provide environment information

- OS: Linux

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

Backend, Types

Auth config (if applicable)

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "sqlite",
    schema
  }), 
  emailAndPassword: {  
    enabled: true
  },
  user: {
    additionalFields: {
      role: {
        type: "string",
        input: false,
        required: true,
        defaultValue: "user",
      },
    }
  }
})

Additional context

No response

Originally created by @eyadfareh on GitHub (May 16, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. define user and set an additional fields with a default value for drizzle 2. `npx @better-auth/cli generate` 3. the generated schema doesn't put the default value inside a string 4. it results in invalid drizzle schema the schema it produces: ```ts export const user = sqliteTable("user", { id: text('id').primaryKey(), name: text('name').notNull(), email: text('email').notNull().unique(), emailVerified: integer('email_verified', { mode: 'boolean' }).$defaultFn(() => false).notNull(), image: text('image'), createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => /* @__PURE__ */ new Date()).notNull(), updatedAt: integer('updated_at', { mode: 'timestamp' }).$defaultFn(() => /* @__PURE__ */ new Date()).notNull(), role: text('role').default(user).notNull() }); ``` instead of ```ts role: text('role').default("user").notNull() ``` ### Current vs. Expected behavior the default value should be a string, but instead it is an identifier. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - OS: Linux ``` ### Which area(s) are affected? (Select all that apply) Backend, Types ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "sqlite", schema }), emailAndPassword: { enabled: true }, user: { additionalFields: { role: { type: "string", input: false, required: true, defaultValue: "user", }, } } }) ``` ### Additional context _No response_
Author
Owner

@devallibus commented on GitHub (May 18, 2025):

Can confirm this is also happening to me. Can fix manually by editing the schema, but not ideal.

@devallibus commented on GitHub (May 18, 2025): Can confirm this is also happening to me. Can fix manually by editing the schema, but not ideal.
Author
Owner

@Kinfe123 commented on GitHub (May 28, 2025):

it is already fixed will be up in upcoming releases! till then you can use the beta version for that

@Kinfe123 commented on GitHub (May 28, 2025): it is already fixed will be up in upcoming releases! till then you can use the beta version for that
Author
Owner

@bookercodes commented on GitHub (Jun 3, 2025):

I just ran into this issue. Great to learn it's been fixed already in the newest (beta) version!

@bookercodes commented on GitHub (Jun 3, 2025): I just ran into this issue. Great to learn it's been fixed already in the newest (beta) version!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1213