[GH-ISSUE #4043] additional fields not inserted into db #18438

Closed
opened 2026-04-15 16:53:19 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @hrithiqball on GitHub (Aug 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4043

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. load the config

  2. have this in prisma schema

model user {
  id            String   @id
  name          String
  email         String   @unique
  emailVerified Boolean  @default(false)
  image         String?
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt
  role          ROLE[]   @default([HUSTLR])
  gender        GENDER?
  phone         String?

  session session[]
  account account[]
}
  1. send this curl request
curl --location 'http://localhost:8787/api/auth/sign-up/email' \
--header 'Content-Type: application/json' \
--header 'Cookie: __Secure-better-auth.session_token=SPfVfKsV32HMCyP4sh1mhevInbAmQKvd.v4iXf9Lu0lcSNpDfz%2BHCfWKHEweqC0vEueyklbhA5Vk%3D' \
--data-raw '{
  "name": "Prisma",
  "email": "prisma6@pixcel.org",
  "password": "password",
  "image": "",
  "gender": "MALE",
  "phone": "+60179611822"
}'

Current vs. Expected behavior

im expecting phone and gender in my database however

Image

What version of Better Auth are you using?

1.3.6

System info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 18.44 GB / 31.22 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Browsers:
    Chrome: 139.0.7258.127

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

Backend

Auth config (if applicable)

export const auth = (environment: CloudflareBindings) => {
  const prisma = getPrisma(environment)

  return betterAuth({
    database: prismaAdapter(prisma, { provider: 'postgresql' }),
    baseURL: environment.BETTER_AUTH_URL,
    secret: environment.BETTER_AUTH_SECRET,
    user: {
      additionalFields: {
        role: {
          type: 'string[]',
          required: true,
          defaultValue: ['HUSTLR'],
          input: false
        },
        gender: {
          type: 'string',
          required: true,
          defaultValue: '',
          input: true
        },
        phone: {
          type: 'string',
          required: false,
          defaultValue: '',
          input: true
        }
      }
    },
    emailAndPassword: {
      enabled: true,
      password: {
        async hash(password) {
          const salt = randomBytes(16)
          const hash = pbkdf2Sync(password, salt, 1000, 32, 'sha256')

          return `${salt.toString('hex')}:${hash.toString('hex')}`
        },
        async verify({ hash, password }) {
          const [saltHex, storedHashHex] = hash.split(':')
          const salt = Buffer.from(saltHex, 'hex')
          const storedHash = Buffer.from(storedHashHex, 'hex')

          const testHash = pbkdf2Sync(password, salt, 1000, 32, 'sha256')
          return storedHash.equals(testHash)
        }
      }
    },
    plugins: [openAPI()],
    databaseHooks: {
      user: {
        create: {
          async before(user) {
            return { data: { ...user, phone: 'not inserted' } }
          }
        }
      }
    }
  })
}

Additional context

No response

Originally created by @hrithiqball on GitHub (Aug 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4043 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. load the config 2. have this in prisma schema ```prisma model user { id String @id name String email String @unique emailVerified Boolean @default(false) image String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt role ROLE[] @default([HUSTLR]) gender GENDER? phone String? session session[] account account[] } ``` 3. send this curl request ```bash curl --location 'http://localhost:8787/api/auth/sign-up/email' \ --header 'Content-Type: application/json' \ --header 'Cookie: __Secure-better-auth.session_token=SPfVfKsV32HMCyP4sh1mhevInbAmQKvd.v4iXf9Lu0lcSNpDfz%2BHCfWKHEweqC0vEueyklbhA5Vk%3D' \ --data-raw '{ "name": "Prisma", "email": "prisma6@pixcel.org", "password": "password", "image": "", "gender": "MALE", "phone": "+60179611822" }' ``` ### Current vs. Expected behavior im expecting phone and gender in my database however <img width="772" height="364" alt="Image" src="https://github.com/user-attachments/assets/f36bf92e-b8b4-4f22-ab5d-0802baebcb9d" /> ### What version of Better Auth are you using? 1.3.6 ### System info ```bash System: OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm) CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor Memory: 18.44 GB / 31.22 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Browsers: Chrome: 139.0.7258.127 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = (environment: CloudflareBindings) => { const prisma = getPrisma(environment) return betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql' }), baseURL: environment.BETTER_AUTH_URL, secret: environment.BETTER_AUTH_SECRET, user: { additionalFields: { role: { type: 'string[]', required: true, defaultValue: ['HUSTLR'], input: false }, gender: { type: 'string', required: true, defaultValue: '', input: true }, phone: { type: 'string', required: false, defaultValue: '', input: true } } }, emailAndPassword: { enabled: true, password: { async hash(password) { const salt = randomBytes(16) const hash = pbkdf2Sync(password, salt, 1000, 32, 'sha256') return `${salt.toString('hex')}:${hash.toString('hex')}` }, async verify({ hash, password }) { const [saltHex, storedHashHex] = hash.split(':') const salt = Buffer.from(saltHex, 'hex') const storedHash = Buffer.from(storedHashHex, 'hex') const testHash = pbkdf2Sync(password, salt, 1000, 32, 'sha256') return storedHash.equals(testHash) } } }, plugins: [openAPI()], databaseHooks: { user: { create: { async before(user) { return { data: { ...user, phone: 'not inserted' } } } } } } }) } ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:53:19 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Aug 21, 2025):

was the response 200 when you do curl request and got some response back ? also can you try it with-out the role being type string[] ?

<!-- gh-comment-id:3210007294 --> @Kinfe123 commented on GitHub (Aug 21, 2025): was the response 200 when you do curl request and got some response back ? also can you try it with-out the role being type `string[]` ?
Author
Owner

@hrithiqball commented on GitHub (Aug 21, 2025):

@Kinfe123 yup response is 200 ok, user is actually created. the only reason role is having value is because i set default values as that array. the issue is even though i put phone and gender in curl request. they wont be insert into db

<!-- gh-comment-id:3211095893 --> @hrithiqball commented on GitHub (Aug 21, 2025): @Kinfe123 yup response is 200 ok, user is actually created. the only reason role is having value is because i set default values as that array. the issue is even though i put phone and gender in curl request. they wont be insert into db
Author
Owner

@Kinfe123 commented on GitHub (Aug 21, 2025):

can you look in to your database hook are actually getting the user object and can you show me what you get from that ?

<!-- gh-comment-id:3211304486 --> @Kinfe123 commented on GitHub (Aug 21, 2025): can you look in to your database hook are actually getting the user object and can you show me what you get from that ?
Author
Owner

@Kinfe123 commented on GitHub (Sep 9, 2025):

I cant reproduce this issue but feel free to tag if the issue persists and happy to review it once again with minimal repro

<!-- gh-comment-id:3271417455 --> @Kinfe123 commented on GitHub (Sep 9, 2025): I cant reproduce this issue but feel free to tag if the issue persists and happy to review it once again with minimal repro
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18438