[GH-ISSUE #7419] Error when signing up with email and password while using { mode: "string" } for timestamps in Drizzle adapter #19440

Open
opened 2026-04-15 18:31:41 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @namuorg on GitHub (Jan 16, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7419

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use a Drizzle schema where timestamp uses { mode: "string" } for createdAt or updatedAt in the users table
  2. Try to sign up as a new user using email and password

Current vs. Expected behavior

Expected behavior

No error

Actual behavior

Error:

2026-01-16T16:50:54.888Z ERROR [Better Auth]: Failed to create user Error: Failed query: insert into "users"
    ("id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at")
     values ($1, $2, $3, $4, default, $5, $6, default, default, $7, $8) returning "id", "name", "email", "email_verified",
    "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at"
params: 019bc7b7-904c-71ae-ac9c-ec6912163032,Test User 2,test-user-67890@example.com,false,user,false,Fri Jan 16 2026 08:50:54 GMT-0800 (Pacific Standard Time),Fri Jan 16 2026 08:50:54 GMT-0800 (Pacific Standard Time) at ignore-listed frames {
  query: 'insert into "users" ("id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at") values ($1, $2, $3, $4, default, $5, $6, default, default, $7, $8)
    returning "id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at"',
  params: [Array],
  [cause]: TypeError: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer.
    Received an instance of Date
      at ignore-listed frames {
    code: 'ERR_INVALID_ARG_TYPE'
  }
}

Key lines:

[cause]: TypeError: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer.
    Received an instance of Date
      at ignore-listed frames {
    code: 'ERR_INVALID_ARG_TYPE'
  }

What version of Better Auth are you using?

1.4.3

System info

N/A

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

Backend

Auth config (if applicable)

N/A

Additional context

This issue was originally reported in this comment: https://github.com/better-auth/better-auth/issues/1418#issuecomment-2708499572

The fix that closed that issue (https://github.com/better-auth/better-auth/pull/5042) actually doesn't address the problem reported in this issue.

That fix addresses the issue where the user has a schema using { mode: "date" } (the default) and better-auth fails to convert strings back to Date before inserting into the table.

This issue is about the user having a schema of { mode: "string" } and better-auth trying to insert Dates into the table when it should be inserting a string.

Originally created by @namuorg on GitHub (Jan 16, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7419 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use a Drizzle schema where timestamp uses [`{ mode: "string" }`](https://orm.drizzle.team/docs/column-types/pg#timestamp) for `createdAt` or `updatedAt` in the users table 2. Try to sign up as a new user using email and password ### Current vs. Expected behavior ### Expected behavior No error ### Actual behavior Error: ``` 2026-01-16T16:50:54.888Z ERROR [Better Auth]: Failed to create user Error: Failed query: insert into "users" ("id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at") values ($1, $2, $3, $4, default, $5, $6, default, default, $7, $8) returning "id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at" params: 019bc7b7-904c-71ae-ac9c-ec6912163032,Test User 2,test-user-67890@example.com,false,user,false,Fri Jan 16 2026 08:50:54 GMT-0800 (Pacific Standard Time),Fri Jan 16 2026 08:50:54 GMT-0800 (Pacific Standard Time) at ignore-listed frames { query: 'insert into "users" ("id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at") values ($1, $2, $3, $4, default, $5, $6, default, default, $7, $8) returning "id", "name", "email", "email_verified", "image", "role", "banned", "ban_reason", "ban_expires", "created_at", "updated_at"', params: [Array], [cause]: TypeError: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date at ignore-listed frames { code: 'ERR_INVALID_ARG_TYPE' } } ``` Key lines: ``` [cause]: TypeError: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date at ignore-listed frames { code: 'ERR_INVALID_ARG_TYPE' } ``` ### What version of Better Auth are you using? 1.4.3 ### System info ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript N/A ``` ### Additional context This issue was originally reported in this comment: https://github.com/better-auth/better-auth/issues/1418#issuecomment-2708499572 The fix that closed that issue (https://github.com/better-auth/better-auth/pull/5042) actually doesn't address the problem reported in this issue. That fix addresses the issue where the user has a schema using `{ mode: "date" }` (the default) and `better-auth` fails to convert strings back to `Date` before inserting into the table. This issue is about the user having a schema of `{ mode: "string" }` and `better-auth` trying to insert `Date`s into the table when it should be inserting a string.
GiteaMirror added the databasecredentialsbug labels 2026-04-15 18:31:42 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 16, 2026):

It seems you're encountering an issue with the Drizzle schema using { mode: "string" } for timestamps. The error you're seeing suggests that Better Auth is attempting to use a Date instance where a string is expected. This could be related to how the Drizzle adapter is handling the conversion of date fields.

To troubleshoot further, you might want to check the following:

  1. Ensure Your Schema is Correct: Verify that the timestamp fields in your schema are appropriately defined to accept string formats. The Drizzle adapter should be configured to manage these types correctly.

  2. Check Compatibility: The Better Auth version you're using (1.4.3) may have known issues with the way it handles date parsing. There are open issues that discuss similar problems with date handling in the Drizzle adapter.

  3. Consider Open Issues: You might want to follow or comment on open issues related to this error, as there are discussions about supporting string formats for timestamps and ensuring proper date handling [1], [3].

If the issue persists, I recommend tagging @bekacru or @ping__ in your comments, as they can provide help with specific questions or deeper issues related to your implementation.

Have you tried adjusting your schema and the options in your Drizzle adapter configuration? Let me know how it goes or if you have any other questions!

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3761011964 --> @better-auth-agent[bot] commented on GitHub (Jan 16, 2026): It seems you're encountering an issue with the Drizzle schema using `{ mode: "string" }` for timestamps. The error you're seeing suggests that Better Auth is attempting to use a `Date` instance where a string is expected. This could be related to how the Drizzle adapter is handling the conversion of date fields. To troubleshoot further, you might want to check the following: 1. **Ensure Your Schema is Correct**: Verify that the timestamp fields in your schema are appropriately defined to accept string formats. The Drizzle adapter should be configured to manage these types correctly. 2. **Check Compatibility**: The Better Auth version you're using (1.4.3) may have known issues with the way it handles date parsing. There are open issues that discuss similar problems with date handling in the Drizzle adapter. 3. **Consider Open Issues**: You might want to follow or comment on open issues related to this error, as there are discussions about supporting string formats for timestamps and ensuring proper date handling [[1]](https://github.com/better-auth/better-auth/pull/6518), [[3]](https://github.com/better-auth/better-auth/issues/6779). If the issue persists, I recommend tagging @bekacru or @ping__ in your comments, as they can provide help with specific questions or deeper issues related to your implementation. Have you tried adjusting your schema and the options in your Drizzle adapter configuration? Let me know how it goes or if you have any other questions! _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/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 16, 2026):

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

Better Auth does not currently support automatic conversion of JavaScript Date objects to strings for Drizzle schemas with { mode: "string" } timestamps. This is why you see a TypeError when trying to insert a user: the adapter passes Date objects directly to the database, but Drizzle expects ISO8601 strings for these fields. The previous fix you referenced only addressed converting string inputs to Date objects, not the reverse problem of serializing Dates to strings for DB insertion.

As a workaround, you can manually convert any Date fields to ISO strings (using .toISOString()) before passing them to Better Auth when your schema uses { mode: "string" } for timestamps. For a proper fix, Better Auth would need to add logic to detect these fields and serialize Dates to strings before insertion—either in the internal adapter or the Drizzle adapter itself. This pattern is already used in other parts of the codebase, such as the OIDC provider plugin, but not yet in the Drizzle adapter (source, source).

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:3761026152 --> @dosubot[bot] commented on GitHub (Jan 16, 2026): <!-- Greeting --> Hi @namuorg! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Better Auth does not currently support automatic conversion of JavaScript Date objects to strings for Drizzle schemas with `{ mode: "string" }` timestamps. This is why you see a TypeError when trying to insert a user: the adapter passes Date objects directly to the database, but Drizzle expects ISO8601 strings for these fields. The previous fix you referenced only addressed converting string inputs to Date objects, not the reverse problem of serializing Dates to strings for DB insertion. As a workaround, you can manually convert any Date fields to ISO strings (using `.toISOString()`) before passing them to Better Auth when your schema uses `{ mode: "string" }` for timestamps. For a proper fix, Better Auth would need to add logic to detect these fields and serialize Dates to strings before insertion—either in the internal adapter or the Drizzle adapter itself. This pattern is already used in other parts of the codebase, such as the OIDC provider plugin, but not yet in the Drizzle adapter ([source](https://github.com/better-auth/better-auth/pull/4176), [source](https://github.com/better-auth/better-auth/blob/032ead4790e64977ff7c10273ea94cb9d624f4ac/packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts#L35-L606)). <!-- 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/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bd07cb70-0a84-4d9f-ad52-20fc003459f3?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=Better%20Auth%20does%20not%20currently%20support%20automatic%20conversion%20of%20JavaScript%20Date%20objects%20to%20strings%20for%20Drizzle%20schemas%20with%20%60%7B%20mode%3A%20%22string%22%20%7D%60%20timestamps.%20This%20is%20why%20you%20see%20a%20TypeError%20when%20trying%20to%20insert%20a%20user%3A%20the%20adapter%20passes%20Date%20objects%20directly%20to%20the%20database%2C%20but%20Drizzle%20expects%20ISO8601%20strings%20for%20these%20fields.%20The%20previous%20fix%20you%20referenced%20only%20addressed%20converting%20string%20inputs%20to%20Date%20objects%2C%20not%20the%20reverse%20problem%20of%20serializing%20Dates%20to%20strings%20for%20DB%20insertion.%0A%0AAs%20a%20workaround%2C%20you%20can%20manually%20convert%20any%20Date%20fields%20to%20ISO%20strings%20%28using%20%60.toISOString%28%29%60%29%20before%20passing%20them%20to%20Better%20Auth%20when%20your%20schema%20uses%20%60%7B%20mode%3A%20%22string%22%20%7D%60%20for%20timestamps.%20For%20a%20proper%20fix%2C%20Better%20Auth%20would%20need%20to%20add%20logic%20to%20detect%20these%20fields%20and%20serialize%20Dates%20to%20strings%20before%20insertion%E2%80%94either%20in%20the%20internal%20adapter%20or%20the%20Drizzle%20adapter%20itself.%20This%20pattern%20is%20already%20used%20in%20other%20parts%20of%20the%20codebase%2C%20such%20as%20the%20OIDC%20provider%20plugin%2C%20but%20not%20yet%20in%20the%20Drizzle%20adapter%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/pull/4176%29%2C%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/032ead4790e64977ff7c10273ea94cb9d624f4ac/packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts%23L35-L606%29%29.)&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/7419)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19440