[PR #5042] [MERGED] fix: unsanitized endpoints provided dates will cause DB insert failure #22634

Closed
opened 2026-04-15 21:11:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5042
Author: @ping-maxwell
Created: 10/2/2025
Status: Merged
Merged: 11/5/2025
Merged by: @Bekacru

Base: canaryHead: fix/sign-up-email-date-additional-field


📝 Commits (10+)

  • 5ba0e09 reafactor: move user input parser to api endpoints
  • 2eafb78 chore: remove log
  • 9755868 fix: sign-up-email provided dates will cause DB insert failure
  • 88e4c58 Merge branch 'canary' into fix/sign-up-email-date-additional-field
  • 72778e7 chore: improve if checks
  • 4866863 chore: lint
  • 9c80ac9 fix: change req
  • 74e0605 Merge branch 'canary' into fix/sign-up-email-date-additional-field
  • c62551b chore: lint
  • 39ab06c Merge branch 'canary' into fix/sign-up-email-date-additional-field

📊 Changes

2 files changed (+80 additions, -55 deletions)

View changed files

📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+21 -1)
📝 packages/better-auth/src/adapters/tests/auth-flow.ts (+59 -54)

📄 Description

When creating an additional field with a type of date, then using the authClient.signUp.email with that new date field, the endpoint will fail saying it couldn't insert a user. The error will be value.toIsoString is not a function.

This is caused by the client sending dates to the server as a string (since it can't send Date type over HTTP). Normally, our endpoints which have Zod validation will automatically convert dates from string back to dates, however since the signUpEmail (and other) endpoint doesn't do this it causes bugs when inserting.

This PR fixes this and adds tests.

closes https://github.com/better-auth/better-auth/issues/1418 & https://github.com/better-auth/better-auth/issues/5032


Summary by cubic

Fixes signUpEmail failing when a user additional field is a date. String date inputs are now converted to Date before DB insert so sign-up works reliably.

  • Bug Fixes

    • Convert string values to Date for fields with type "date" in the adapter factory.
    • signUpEmail accepts date additional fields without throwing “value.toIsoString is not a function”.
  • Refactors

    • Added test coverage for sign-up with a date additional field and session retrieval.
    • Simplified test setup with default auth options and a Set-Cookie → Cookie helper.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5042 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/2/2025 **Status:** ✅ Merged **Merged:** 11/5/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/sign-up-email-date-additional-field` --- ### 📝 Commits (10+) - [`5ba0e09`](https://github.com/better-auth/better-auth/commit/5ba0e093ecd46b83bf9a593251164206ee2ba623) reafactor: move user input parser to api endpoints - [`2eafb78`](https://github.com/better-auth/better-auth/commit/2eafb786b78f3ebe045fb641263a8227652e87b4) chore: remove log - [`9755868`](https://github.com/better-auth/better-auth/commit/975586894369f21eed808303c0e2836ef010cf1f) fix: sign-up-email provided dates will cause DB insert failure - [`88e4c58`](https://github.com/better-auth/better-auth/commit/88e4c58cea6b3ac206254e5cbdd09fa0c853f55f) Merge branch 'canary' into fix/sign-up-email-date-additional-field - [`72778e7`](https://github.com/better-auth/better-auth/commit/72778e7690fcdfe0381cab2fc96901a19c4d07f3) chore: improve if checks - [`4866863`](https://github.com/better-auth/better-auth/commit/486686347327a5d57796ea19132b7166b13ba0a3) chore: lint - [`9c80ac9`](https://github.com/better-auth/better-auth/commit/9c80ac9ff77b263f0cf9c530da51039dfd245f85) fix: change req - [`74e0605`](https://github.com/better-auth/better-auth/commit/74e06056e2060fa6d746bc50a7c1fadb40cc3fcc) Merge branch 'canary' into fix/sign-up-email-date-additional-field - [`c62551b`](https://github.com/better-auth/better-auth/commit/c62551bf442d7f2c75872fb7f13b97d8eb93e638) chore: lint - [`39ab06c`](https://github.com/better-auth/better-auth/commit/39ab06cd4a92b700d3eac34c04cc8c86395fa827) Merge branch 'canary' into fix/sign-up-email-date-additional-field ### 📊 Changes **2 files changed** (+80 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+21 -1) 📝 `packages/better-auth/src/adapters/tests/auth-flow.ts` (+59 -54) </details> ### 📄 Description When creating an additional field with a type of `date`, then using the `authClient.signUp.email` with that new date field, the endpoint will fail saying it couldn't insert a user. The error will be `value.toIsoString` is not a function. This is caused by the client sending dates to the server as a string (since it can't send Date type over HTTP). Normally, our endpoints which have Zod validation will automatically convert dates from string back to dates, however since the signUpEmail (and other) endpoint doesn't do this it causes bugs when inserting. This PR fixes this and adds tests. closes https://github.com/better-auth/better-auth/issues/1418 & https://github.com/better-auth/better-auth/issues/5032 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes signUpEmail failing when a user additional field is a date. String date inputs are now converted to Date before DB insert so sign-up works reliably. - **Bug Fixes** - Convert string values to Date for fields with type "date" in the adapter factory. - signUpEmail accepts date additional fields without throwing “value.toIsoString is not a function”. - **Refactors** - Added test coverage for sign-up with a date additional field and session retrieval. - Simplified test setup with default auth options and a Set-Cookie → Cookie helper. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 21:11:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#22634