Skip to content

Conversation

@juliesaia
Copy link
Contributor

@juliesaia juliesaia commented Dec 20, 2025

This PR enables supportsDates in the adapter config.

With supportsDates: false, better-auth automatically converts dates to ISO strings (see @better-auth/core/src/db/adapter/factory.ts). This breaks all the logic in this package that relies on instanceof Date to convert them to timestamp numbers instead.

With supportsDates: true, the existing logic to convert to timestamps can run.

There's probably more bugs downstream of this, but the one I came across was the reset password flow not working. By default better-auth cleans all expired verification tokens when fetching a token. With the broken logic, it was trying to do lt: '2025-12-20... which was always true. So when the user tries to submit the token to reset their password, its already deleted...


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@vercel
Copy link

vercel bot commented Dec 20, 2025

@juliesaia is attempting to deploy a commit to the Convex Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Dec 20, 2025

Walkthrough

The convex adapter configuration is updated to set supportsDates to true, enabling better-auth to apply custom date transforms that convert dates to numbers instead of ISO strings, while existing custom transform logic remains in place.

Changes

Cohort / File(s) Summary
Convex adapter date support
src/client/adapter.ts
Set supportsDates configuration to true to enable date-to-number transformations via better-auth's custom date handlers

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A tiny flag flipped true with care,
Dates now dance through numeric air,
Numbers bloom where ISO strings once grew,
The rabbit hops—one change will do! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enabling supportsDates to prevent better-auth from converting dates to ISO strings, which aligns with the core fix in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/client/adapter.ts (1)

87-97: Date handling is consistent with custom transforms.

The parseWhere function correctly converts Date instances to timestamps using getTime(), which aligns with the custom transform behavior. This ensures consistent date handling throughout the adapter.

Optional: Consider adding validation for invalid dates in both parseWhere and the custom transforms, since new Date(invalidValue).getTime() returns NaN. However, this is a pre-existing consideration and can be addressed separately if needed.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 920ec5e and f833a0b.

📒 Files selected for processing (1)
  • src/client/adapter.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2025-12-20T00:20:00.408Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: examples/next/.cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-20T00:20:00.408Z
Learning: Applies to examples/next/convex/**/*.{ts,tsx} : Use `v.int64()` instead of the deprecated `v.bigint()` for representing signed 64-bit integers

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-20T00:20:00.408Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: examples/next/.cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-20T00:20:00.408Z
Learning: Applies to examples/next/convex/**/*.{ts,tsx} : ALWAYS use the new function syntax for Convex functions with `query`, `mutation`, or `action` decorators, including `args`, `returns`, and `handler` properties

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-20T00:20:00.408Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: examples/next/.cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-20T00:20:00.408Z
Learning: Applies to examples/next/convex/**/*.{ts,tsx} : Convex storage stores items as `Blob` objects. You must convert all items to/from a `Blob` when using Convex storage

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-20T00:20:00.408Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: examples/next/.cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-20T00:20:00.408Z
Learning: Applies to examples/next/convex/**/*.{ts,tsx} : Use `v.record()` for defining record types; `v.map()` and `v.set()` are not supported in Convex

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-16T22:34:45.580Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-16T22:34:45.580Z
Learning: Applies to convex/schema.ts : System fields `_creationTime` and `_id` are automatically added to all documents. Use validators `v.number()` for `_creationTime` and `v.id(tableName)` for `_id`

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-20T00:20:00.408Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: examples/next/.cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-20T00:20:00.408Z
Learning: Applies to examples/next/convex/**/*.{ts,tsx} : By default Convex always returns documents in ascending `_creationTime` order

Applied to files:

  • src/client/adapter.ts
📚 Learning: 2025-12-16T22:34:45.581Z
Learnt from: CR
Repo: get-convex/better-auth PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-12-16T22:34:45.581Z
Learning: Applies to convex/**/*.ts : By default Convex always returns documents in ascending `_creationTime` order. Use `.order('asc')` or `.order('desc')` to pick the order

Applied to files:

  • src/client/adapter.ts
🔇 Additional comments (1)
src/client/adapter.ts (1)

132-149: Fix looks correct and addresses the root cause.

The change from supportsDates: false to supportsDates: true properly enables the custom date transformation logic. With this change:

  • better-auth's date transformations are applied before customTransformInput, allowing the custom transforms to convert dates to numeric timestamps
  • The parseWhere function (line 89) can successfully use instanceof Date checks
  • Custom transforms convert dates to millisecond timestamps, which Convex supports natively
  • Date comparisons work correctly as numeric operations instead of string comparisons

This fixes the reported reset password flow failure where ISO string comparisons like lt: '2025-12-20...' were incorrectly evaluating.

@l3dotdev
Copy link

Related #206

@erquhart
Copy link
Collaborator

Thanks for opening this @juliesaia! This was an upstream bug, fixed in better-auth 1.4.8, and we now test for proper date handling as well. We do want to keep supportsDates: false because Convex doesn't support actual JS dates, so it's better that they not be passed to the adapter in the first place.

@erquhart erquhart closed this Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants