[Kysely] Renamed model or field causes query error with SQLite #1599

Closed
opened 2026-03-13 08:50:42 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @ntharim on GitHub (Jul 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Rename verification field expiresAt to "expires_at"
  2. Add passkey via authClient.passkey.addPasskey(...)

Current vs. Expected behavior

Current:

/api/auth/passkey/verify-registration fails with database error TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null.

Expected:

Successful completion.

What version of Better Auth are you using?

1.3.4

Provide environment information

- OS: NixOS
- browser: Firefox 139

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { passkey } from "better-auth/plugins/passkey";
import Database from "better-sqlite3";

export const auth = betterAuth({
  plugins: [
    passkey(),
  ],
  emailAndPassword: {
    enabled: true,
  },
  verification: {
    fields: {
      expiresAt: "expires_at"
    }
  },
  database: new Database("database.sqlite"),
});

Additional context

It seems to be because the Kysely adapter is not correctly transforming the Date value for renamed models and fields. This line should find and return the renamed field instead of just the model:

259184641e/packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (L97)

Originally created by @ntharim on GitHub (Jul 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Rename `verification` field `expiresAt` to `"expires_at"` 2. Add passkey via `authClient.passkey.addPasskey(...)` ### Current vs. Expected behavior Current: `/api/auth/passkey/verify-registration` fails with database error `TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null`. Expected: Successful completion. ### What version of Better Auth are you using? 1.3.4 ### Provide environment information ```bash - OS: NixOS - browser: Firefox 139 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { passkey } from "better-auth/plugins/passkey"; import Database from "better-sqlite3"; export const auth = betterAuth({ plugins: [ passkey(), ], emailAndPassword: { enabled: true, }, verification: { fields: { expiresAt: "expires_at" } }, database: new Database("database.sqlite"), }); ``` ### Additional context It seems to be because the Kysely adapter is not correctly transforming the `Date` value for renamed models and fields. This line should find and return the renamed field instead of just the model: https://github.com/better-auth/better-auth/blob/259184641e24a7df6efdd7200c16654307c81b4b/packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts#L97
GiteaMirror added the adapter label 2026-03-13 08:50:42 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 29, 2025):

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

You’re right—this is a bug in the Kysely adapter’s handling of renamed fields. The transformValueToDB function only checks the original field name in the schema and doesn’t resolve renamed fields before deciding how to serialize values. As a result, when you rename a field like expiresAt to expires_at, the adapter fails to recognize it as a Date and passes a raw Date object to SQLite, which triggers the error: “SQLite3 can only bind numbers, strings, bigints, buffers, and null” reference.

A practical workaround is to patch transformValueToDB so it resolves the logical field name (e.g., expiresAt) to the mapped DB column (e.g., expires_at) before looking up the field type and serializing. You can do this by ensuring the function uses the same mapping logic as getFieldName, or by manually serializing Date fields to strings before passing them to the adapter.

For a robust fix, the adapter should always resolve the mapped field name before transforming values, just like it does in other parts of the code (e.g., convertWhereClause). Updating transformValueToDB to use getFieldName or similar logic would ensure renamed fields are handled correctly for all types, especially Date fields with SQLite.

Let me know if you want a code snippet for a local patch or want to discuss a more permanent fix!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 29, 2025): <!-- Greeting --> Hi @ntharim! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You’re right—this is a bug in the Kysely adapter’s handling of renamed fields. The transformValueToDB function only checks the original field name in the schema and doesn’t resolve renamed fields before deciding how to serialize values. As a result, when you rename a field like expiresAt to expires_at, the adapter fails to recognize it as a Date and passes a raw Date object to SQLite, which triggers the error: “SQLite3 can only bind numbers, strings, bigints, buffers, and null” [reference](https://github.com/better-auth/better-auth/blob/ecb4408c41fb05a1f988a113882b1806267e6af5/packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts). A practical workaround is to patch transformValueToDB so it resolves the logical field name (e.g., expiresAt) to the mapped DB column (e.g., expires_at) before looking up the field type and serializing. You can do this by ensuring the function uses the same mapping logic as getFieldName, or by manually serializing Date fields to strings before passing them to the adapter. For a robust fix, the adapter should always resolve the mapped field name before transforming values, just like it does in other parts of the code (e.g., convertWhereClause). Updating transformValueToDB to use getFieldName or similar logic would ensure renamed fields are handled correctly for all types, especially Date fields with SQLite. Let me know if you want a code snippet for a local patch or want to discuss a more permanent fix! <!-- 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/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7f4bee5d-9252-4e9b-93dc-498d4eae0f89?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/3683)
Author
Owner

@wamujlb commented on GitHub (Sep 29, 2025):

hey @ntharim. Were you able to come up with a workaround? I have tried writing the custom plugin, databaseHooks, but no success.

@wamujlb commented on GitHub (Sep 29, 2025): hey @ntharim. Were you able to come up with a workaround? I have tried writing the custom plugin, databaseHooks, but no success.
Author
Owner

@ping-maxwell commented on GitHub (Oct 7, 2025):

Related: https://github.com/better-auth/better-auth/issues/4805

@ping-maxwell commented on GitHub (Oct 7, 2025): Related: https://github.com/better-auth/better-auth/issues/4805
Author
Owner

@ping-maxwell commented on GitHub (Oct 7, 2025):

I've found the cause and am working on a fix.

@ping-maxwell commented on GitHub (Oct 7, 2025): I've found the cause and am working on a fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1599