-
Notifications
You must be signed in to change notification settings - Fork 82
(fix) Prevent better-auth from converting dates to ISO strings #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@juliesaia is attempting to deploy a commit to the Convex Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe convex adapter configuration is updated to set Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
parseWherefunction correctly converts Date instances to timestamps usinggetTime(), which aligns with the custom transform behavior. This ensures consistent date handling throughout the adapter.Optional: Consider adding validation for invalid dates in both
parseWhereand the custom transforms, sincenew Date(invalidValue).getTime()returnsNaN. However, this is a pre-existing consideration and can be addressed separately if needed.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 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: falsetosupportsDates: trueproperly 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
parseWherefunction (line 89) can successfully useinstanceof Datechecks- 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.
|
Related #206 |
|
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 |
This PR enables
supportsDatesin 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 oninstanceof Dateto 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.