[GH-ISSUE #6629] verification table does not merge additionalFields #10575

Closed
opened 2026-04-13 06:48:36 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @msickpaler on GitHub (Dec 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6629

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Define additionalFields in the verification table like below.
const auth = betterAuth({
  verification: {
    additionalFields: {
      verificationId: {
        type: "string",
        required: true,
        input: true,
        fieldName: "verification_id",
      },
    },
  },
});
  1. Set verificationId in the verification.create.before hook using databaseHooks
const auth = betterAuth({
  // ...
  databaseHooks: {
    verification: {
      create: {
        before: async (data, request) => {
          const id = ulid();
          return { data: { ...data, id: id, verificationId: id } };
        },
      },
    },
  }
})
  1. Confirm that the following error is displayed after call authClient.signIn.social
    null value in column "verification_id" of relation "verification" violates not-null constraint

Current vs. Expected behavior

Current behavior:

  • The additionalFields for the verification table are not applied when new records are created.

Expected behavior:

  • The additionalFields for the verification table should be applied during record creation, just like with user, session, and account.

What version of Better Auth are you using?

1.4.5

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:29:54 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T8122",
    "release": "24.6.0",
    "cpuCount": 8,
    "cpuModel": "Apple M3",
    "totalMemory": "24.00 GB",
    "freeMemory": "0.26 GB"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "express",
      "version": "^4.18.2"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.12.0"
    }
  ],
  "betterAuth": {
    "version": "^1.4.5",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

const { betterAuth } = require("better-auth");
const { ulid } = require("ulid");

const databasePool = new Pool(dbConfig);

const auth = betterAuth({
  baseURL: process.env.BASE_URL,
  database: databasePool,
  secret: process.env.AUTH_SECRET,
  trustedOrigins: process.env.CORS_ORIGIN.split(","),
  socialProviders: {
    google: {
      enabled: true,
      clientId: process.env.AUTH_GOOGLE_CLIENT_ID,
      clientSecret: process.env.AUTH_GOOGLE_CLIENT_SECRET,
    },
  },
  advanced: {
    database: {
      generateId:false,
    },
  },
  verification: {
    modelName: "verification",
    fields: {
      createdAt:'created_at',
      expiresAt:'expires_at',
      identifier:'identifier',
      updatedAt:'updated_at',
      value:'value',
    },
    additionalFields: {
      verificationId: {
        type: "string",
        required: true,
        input: true,
        fieldName: "verification_id",
      },
    },
  },
  databaseHooks: {
    verification: {
      create: {
        before: async (data, request) => {
          const id = ulid();
          return { data: { ...data, id: id, verificationId: id } };
        },
      },
    },
  },
  plugins: [
    magicLink({
      sendMagicLink: sendMagicLinkEmail,
    }),
  ],
});

Additional context

As far as I can tell, the issue is that additionalFields are not being merged in get-tables.ts.

account

additionalFields are merged in account.
fb14141ce3/packages/core/src/db/get-tables.ts (L233C1-L234C42)

verification

additionalFields are not merged in verification.
fb14141ce3/packages/core/src/db/get-tables.ts (L233C1-L234C42)

bug mechanism

getAuthTables is called here.
a9c986a27e/packages/core/src/db/adapter/factory.ts (L84)

transformInput is called here. The data is updated before and after this point.
a9c986a27e/packages/core/src/db/adapter/factory.ts (L836)

Originally created by @msickpaler on GitHub (Dec 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6629 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Define additionalFields in the verification table like below. ```ts const auth = betterAuth({ verification: { additionalFields: { verificationId: { type: "string", required: true, input: true, fieldName: "verification_id", }, }, }, }); ``` 2. Set verificationId in the verification.create.before hook using databaseHooks ```ts const auth = betterAuth({ // ... databaseHooks: { verification: { create: { before: async (data, request) => { const id = ulid(); return { data: { ...data, id: id, verificationId: id } }; }, }, }, } }) ``` 3. Confirm that the following error is displayed after call `authClient.signIn.social` `null value in column "verification_id" of relation "verification" violates not-null constraint` ### Current vs. Expected behavior ### Current behavior: - The additionalFields for the verification table are not applied when new records are created. ### Expected behavior: - The additionalFields for the verification table should be applied during record creation, just like with user, session, and account. ### What version of Better Auth are you using? 1.4.5 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:29:54 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T8122", "release": "24.6.0", "cpuCount": 8, "cpuModel": "Apple M3", "totalMemory": "24.00 GB", "freeMemory": "0.26 GB" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "express", "version": "^4.18.2" } ], "databases": [ { "name": "pg", "version": "^8.12.0" } ], "betterAuth": { "version": "^1.4.5", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript const { betterAuth } = require("better-auth"); const { ulid } = require("ulid"); const databasePool = new Pool(dbConfig); const auth = betterAuth({ baseURL: process.env.BASE_URL, database: databasePool, secret: process.env.AUTH_SECRET, trustedOrigins: process.env.CORS_ORIGIN.split(","), socialProviders: { google: { enabled: true, clientId: process.env.AUTH_GOOGLE_CLIENT_ID, clientSecret: process.env.AUTH_GOOGLE_CLIENT_SECRET, }, }, advanced: { database: { generateId:false, }, }, verification: { modelName: "verification", fields: { createdAt:'created_at', expiresAt:'expires_at', identifier:'identifier', updatedAt:'updated_at', value:'value', }, additionalFields: { verificationId: { type: "string", required: true, input: true, fieldName: "verification_id", }, }, }, databaseHooks: { verification: { create: { before: async (data, request) => { const id = ulid(); return { data: { ...data, id: id, verificationId: id } }; }, }, }, }, plugins: [ magicLink({ sendMagicLink: sendMagicLinkEmail, }), ], }); ``` ### Additional context As far as I can tell, the issue is that additionalFields are not being merged in get-tables.ts. ### account additionalFields are merged in account. https://github.com/better-auth/better-auth/blob/fb14141ce3f6f17c53e8f878662bdfd24201bf9f/packages/core/src/db/get-tables.ts#L233C1-L234C42 ### verification additionalFields are **not** merged in verification. https://github.com/better-auth/better-auth/blob/fb14141ce3f6f17c53e8f878662bdfd24201bf9f/packages/core/src/db/get-tables.ts#L233C1-L234C42 ### bug mechanism getAuthTables is called here. https://github.com/better-auth/better-auth/blob/a9c986a27ec4802c3002a875b9d590d4a285a070/packages/core/src/db/adapter/factory.ts#L84 transformInput is called here. The data is updated before and after this point. https://github.com/better-auth/better-auth/blob/a9c986a27ec4802c3002a875b9d590d4a285a070/packages/core/src/db/adapter/factory.ts#L836 ### related files - https://github.com/better-auth/better-auth/blob/fb14141ce3f6f17c53e8f878662bdfd24201bf9f/packages/better-auth/src/db/internal-adapter.ts#L920 - https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/db/with-hooks.ts#L17 - https://github.com/better-auth/better-auth/blob/fb14141ce3f6f17c53e8f878662bdfd24201bf9f/packages/core/src/db/get-tables.ts - https://github.com/better-auth/better-auth/blob/a9c986a27ec4802c3002a875b9d590d4a285a070/packages/core/src/db/adapter/factory.ts#L49
GiteaMirror added the lockedbug labels 2026-04-13 06:48:37 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 9, 2025):

It looks like the additional fields you defined for the verification model aren’t being merged into the table schema during creation. In the recent version you’re using, the merging logic for account additionalFields is working correctly, but the same logic is not applied for verification – this is evident where the get-tables script merges the fields for account but omits them for verification [1].

A good next step is to check the merging logic in get-tables.ts for the verification model and compare it with the account model’s merging logic. You might need to patch the merging so that the additionalFields (like your verificationId) are included during record creation. As a workaround, ensure that your before hook in the databaseHooks is explicitly assigning the field value before the record is saved, but note that the root issue is that the auto-merge isn’t happening for verification [2].

Have you tried replicating the merging approach from the account model for verification, or would you like guidance on how to update the merge function?

tag @better-auth-agent if you would like an answer from the Agent

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3630444398 --> @better-auth-agent[bot] commented on GitHub (Dec 9, 2025): It looks like the additional fields you defined for the verification model aren’t being merged into the table schema during creation. In the recent version you’re using, the merging logic for account additionalFields is working correctly, but the same logic is not applied for verification – this is evident where the get-tables script merges the fields for account but omits them for verification [[1]](https://github.com/better-auth/better-auth/issues/6446). A good next step is to check the merging logic in get-tables.ts for the verification model and compare it with the account model’s merging logic. You might need to patch the merging so that the additionalFields (like your verificationId) are included during record creation. As a workaround, ensure that your before hook in the databaseHooks is explicitly assigning the field value before the record is saved, but note that the root issue is that the auto-merge isn’t happening for verification [[2]](https://github.com/better-auth/better-auth/issues/1459). Have you tried replicating the merging approach from the account model for verification, or would you like guidance on how to update the merge function? tag @better-auth-agent if you would like an answer from the Agent _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 9, 2025):

Hi @msickpaler! I'm Dosu and I’m helping the better-auth team.

You’re correct—this is a bug in Better Auth v1.4.5. The code in get-tables.ts merges additionalFields for user, session, and account tables, but does not merge them for the verification table. As a result, custom fields like verificationId are not included in the verification schema and cannot be set via hooks, which leads to null constraint errors during record creation. You can see the difference in how the account table uses ...options.account?.additionalFields, while the verification table does not include ...options.verification?.additionalFields in its fields map reference.

There’s no upstream fix or workaround in newer versions or branches as of now. If you need this functionality immediately, you’ll need to patch get-tables.ts locally by adding ...options.verification?.additionalFields to the verification table’s fields definition, similar to how it’s done for account. This will allow your custom fields to be recognized and persisted.

Let me know if you want a code snippet for the patch or have questions about the schema!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3630452021 --> @dosubot[bot] commented on GitHub (Dec 9, 2025): <!-- Greeting --> Hi @msickpaler! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You’re correct—this is a bug in Better Auth v1.4.5. The code in `get-tables.ts` merges `additionalFields` for user, session, and account tables, but does not merge them for the verification table. As a result, custom fields like `verificationId` are not included in the verification schema and cannot be set via hooks, which leads to null constraint errors during record creation. You can see the difference in how the account table uses `...options.account?.additionalFields`, while the verification table does not include `...options.verification?.additionalFields` in its fields map [reference](https://github.com/better-auth/better-auth/blob/b7d3281f910c4131b52a894d3e39b3b8acb5613c/packages/core/src/db/get-tables.ts#L158-L272). There’s no upstream fix or workaround in newer versions or branches as of now. If you need this functionality immediately, you’ll need to patch `get-tables.ts` locally by adding `...options.verification?.additionalFields` to the verification table’s fields definition, similar to how it’s done for account. This will allow your custom fields to be recognized and persisted. Let me know if you want a code snippet for the patch or have questions about the schema! <!-- 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/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1cbdaa30-b650-44db-bcf2-ad1dfca98118?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%E2%80%99re%20correct%E2%80%94this%20is%20a%20bug%20in%20Better%20Auth%20v1.4.5.%20The%20code%20in%20%60get-tables.ts%60%20merges%20%60additionalFields%60%20for%20user%2C%20session%2C%20and%20account%20tables%2C%20but%20does%20not%20merge%20them%20for%20the%20verification%20table.%20As%20a%20result%2C%20custom%20fields%20like%20%60verificationId%60%20are%20not%20included%20in%20the%20verification%20schema%20and%20cannot%20be%20set%20via%20hooks%2C%20which%20leads%20to%20null%20constraint%20errors%20during%20record%20creation.%20You%20can%20see%20the%20difference%20in%20how%20the%20account%20table%20uses%20%60...options.account%3F.additionalFields%60%2C%20while%20the%20verification%20table%20does%20not%20include%20%60...options.verification%3F.additionalFields%60%20in%20its%20fields%20map%C2%A0%5Breference%5D%28https%3A//github.com/better-auth/better-auth/blob/b7d3281f910c4131b52a894d3e39b3b8acb5613c/packages/core/src/db/get-tables.ts%23L158-L272%29.%0A%0AThere%E2%80%99s%20no%20upstream%20fix%20or%20workaround%20in%20newer%20versions%20or%20branches%20as%20of%20now.%20If%20you%20need%20this%20functionality%20immediately%2C%20you%E2%80%99ll%20need%20to%20patch%20%60get-tables.ts%60%20locally%20by%20adding%20%60...options.verification%3F.additionalFields%60%20to%20the%20verification%20table%E2%80%99s%20fields%20definition%2C%20similar%20to%20how%20it%E2%80%99s%20done%20for%20account.%20This%20will%20allow%20your%20custom%20fields%20to%20be%20recognized%20and%20persisted.%0A%0ALet%20me%20know%20if%20you%20want%20a%20code%20snippet%20for%20the%20patch%20or%20have%20questions%20about%20the%20schema%21)&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/6629)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10575