[PR #3611] [MERGED] fix: cast dates from db to Date when using date methods #21814

Closed
opened 2026-04-15 20:37:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3611
Author: @erquhart
Created: 7/25/2025
Status: Merged
Merged: 7/25/2025
Merged by: @Bekacru

Base: nextHead: cast-db-dates


📝 Commits (10+)

  • c83b23c docs(api-key): move schema section to the bottom
  • 4d7676d fix: shouldn't refresh a token if access token expires is undefined or null (#3577)
  • 01814c5 fix: ensure session is added to context when reading from cookie cache (#3578)
  • 59ea6c9 chore: export siwe in better-auth/plugins (#3596)
  • 68f09f1 chore: fix cookies test
  • f27a579 docs: make client-side vs. server-side explicit (#3603)
  • eb0207f docs: fix broken link to ERC-4361 in siwe docs (#3604)
  • f99305b fix(jwt): ensure alg is added to the jwks when generating via /token endpoint (#3601)
  • 786b7b5 fix: cast dates from db to Date when using date methods
  • eb45de5 Merge branch 'next' into cast-db-dates

📊 Changes

8 files changed (+16 additions, -12 deletions)

View changed files

📝 docs/content/docs/concepts/oauth.mdx (+2 -2)
📝 docs/content/docs/plugins/siwe.mdx (+2 -2)
📝 packages/better-auth/src/api/routes/account.ts (+4 -3)
📝 packages/better-auth/src/plugins/admin/admin.ts (+1 -1)
📝 packages/better-auth/src/plugins/api-key/rate-limit.ts (+1 -1)
📝 packages/better-auth/src/plugins/api-key/routes/verify-api-key.ts (+2 -2)
📝 packages/better-auth/src/plugins/jwt/jwt.test.ts (+1 -0)
📝 packages/better-auth/src/plugins/jwt/sign.ts (+3 -1)

📄 Description

A number of places call .getTime() on date values, but adapters using customTransformOutput may transform dates to strings or numbers. This PR wraps those values in the date constructor.

I combed for .getTime() usage specifically, not sure if other methods are also used commonly in the codebase. I also skipped instances involving the context session object as I believe dates in that object are Date types.


Summary by cubic

Fixed issues where date values from the database could be strings or numbers by wrapping them with the Date constructor before using date methods.

  • Bug Fixes
    • Ensured all uses of .getTime() on database date fields work correctly, preventing runtime errors when adapters return non-Date types.

🔄 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/3611 **Author:** [@erquhart](https://github.com/erquhart) **Created:** 7/25/2025 **Status:** ✅ Merged **Merged:** 7/25/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `next` ← **Head:** `cast-db-dates` --- ### 📝 Commits (10+) - [`c83b23c`](https://github.com/better-auth/better-auth/commit/c83b23c6ba7494d5997a06250d48d1777a2fabcf) docs(api-key): move schema section to the bottom - [`4d7676d`](https://github.com/better-auth/better-auth/commit/4d7676d8d9c40a2d5dc30ad2b46810692d3631e8) fix: shouldn't refresh a token if access token expires is undefined or null (#3577) - [`01814c5`](https://github.com/better-auth/better-auth/commit/01814c55e0392ab09f990444fd5e9d5ab81d9e56) fix: ensure session is added to context when reading from cookie cache (#3578) - [`59ea6c9`](https://github.com/better-auth/better-auth/commit/59ea6c9d7919263c1e285500f083c5ce15cdf19d) chore: export siwe in better-auth/plugins (#3596) - [`68f09f1`](https://github.com/better-auth/better-auth/commit/68f09f15d3ef3339ece01f39c9a51bebd8f97010) chore: fix cookies test - [`f27a579`](https://github.com/better-auth/better-auth/commit/f27a5791699315f82926226332ea7535bf9c4aec) docs: make client-side vs. server-side explicit (#3603) - [`eb0207f`](https://github.com/better-auth/better-auth/commit/eb0207f03e7e7538da4c30ba78d22aac9655e294) docs: fix broken link to ERC-4361 in siwe docs (#3604) - [`f99305b`](https://github.com/better-auth/better-auth/commit/f99305b29eb096186a0f85100e01f721d208f2f0) fix(jwt): ensure alg is added to the jwks when generating via /token endpoint (#3601) - [`786b7b5`](https://github.com/better-auth/better-auth/commit/786b7b5e316802325b4a3338ddc79976a0517f2e) fix: cast dates from db to Date when using date methods - [`eb45de5`](https://github.com/better-auth/better-auth/commit/eb45de5255ac9944861f4dc96dadbd9ce1526468) Merge branch 'next' into cast-db-dates ### 📊 Changes **8 files changed** (+16 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/oauth.mdx` (+2 -2) 📝 `docs/content/docs/plugins/siwe.mdx` (+2 -2) 📝 `packages/better-auth/src/api/routes/account.ts` (+4 -3) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/api-key/rate-limit.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/api-key/routes/verify-api-key.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/jwt/jwt.test.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/jwt/sign.ts` (+3 -1) </details> ### 📄 Description A number of places call `.getTime()` on date values, but adapters using `customTransformOutput` may transform dates to strings or numbers. This PR wraps those values in the date constructor. I combed for `.getTime()` usage specifically, not sure if other methods are also used commonly in the codebase. I also skipped instances involving the context session object as I _believe_ dates in that object are Date types. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed issues where date values from the database could be strings or numbers by wrapping them with the Date constructor before using date methods. - **Bug Fixes** - Ensured all uses of `.getTime()` on database date fields work correctly, preventing runtime errors when adapters return non-Date types. <!-- 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 20:37:25 -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#21814