Skip to content

Conversation

@tomsiwik
Copy link

@tomsiwik tomsiwik commented Jan 19, 2026

While this aligns with Convex stored _creationTime & numbers, this should still be transformed back to a Date instance or better-auth handles the formatting wrong (see the invitation bug or reported issue)

Screenshot 2026-01-19 at 23 18 42

fixes #224

Summary by CodeRabbit

  • Bug Fixes

    • Date field outputs now return Date objects instead of numeric timestamps.
  • Tests

    • Added test assertion for date field type validation.

✏️ Tip: You can customize this high-level summary in your review settings.

…ility

while this aligns with Convex stored _creationTime & numbers, this should still be transformed back
to a Date instance or better-auth handles the formatting wrong

fix get-convex#224
@vercel
Copy link

vercel bot commented Jan 19, 2026

@tomsiwik 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 Jan 19, 2026

📝 Walkthrough

Walkthrough

The adapter's custom date field transformation has been updated to return Date objects instead of numeric timestamps. A corresponding test assertion validates this new behavior.

Changes

Cohort / File(s) Summary
Date Transform Update
src/client/adapter.ts
Changed customTransformOutput for date fields from new Date(data).getTime() (numeric timestamp) to new Date(data) (Date object)
Test Assertion
src/component/adapterTest.ts
Added assertion to verify createdAt field is an instance of Date after creation

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Poem

A rabbit hops through dates with glee, 🐰
Timestamps transformed to objects free,
No more numbers in the way,
Date instances save the day! 📅

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR description claims to fix issue #224 by transforming numeric fields back to Date instances, but the linked issue #224 explicitly states the opposite: that invitation.expiresAt should be a number, not a Date. Clarify the actual requirement: determine if invitation.expiresAt should be a Date (as this PR implements) or a number (as issue #224 describes), and ensure the fix aligns with the actual issue requirement.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and specifically describes the main change: converting date field transformations back to Date objects for better-auth compatibility.
Out of Scope Changes check ✅ Passed The changes directly address the stated PR objective of transforming date fields to Date objects, though they appear to conflict with the requirements stated in the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

@tomsiwik
Copy link
Author

@coderabbitai but you seem to not understand that the other side better-auth actually expects Date objects internally. The issue describes what the input after transformation is and what's saved in convex (change unaffected), not what the output should be once retrieved from better-auth

@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Tip

For best results, initiate chat on the files or code changes.

@tomsiwik, thank you for the clarification - you're absolutely right, and I apologize for the confusion. I misunderstood the data flow.

To clarify my understanding now:

Data Flow:

  • Storage in Convex: Dates are stored as numbers (timestamps)
  • Output transformation (this PR): When reading from Convex, customTransformOutput transforms the numeric timestamp back to a Date object
  • better-auth expectation: Internally expects Date objects, not timestamps

The Fix:

  • Previous code: new Date(data).getTime() - transformed to Date then back to number (incorrect for better-auth)
  • New code: new Date(data) - transforms numeric timestamp to Date object (correct for better-auth)

This makes perfect sense now. The PR correctly transforms the numeric values stored in Convex back into Date objects that better-auth expects internally. The issue #224 was occurring because better-auth was receiving numbers instead of Date objects, causing the formatting/typing issues shown in the screenshots.

The fix is appropriate and addresses the root cause. Thank you for the patience in explaining this!


✏️ Learnings added
Learnt from: tomsiwik
URL: https://github.com/get-convex/better-auth/pull/236

Timestamp: 2026-01-19T22:48:52.436Z
Learning: In the Convex adapter for better-auth (src/client/adapter.ts), the `customTransformOutput` function transforms data being read FROM Convex storage TO better-auth's expected format. Since Convex stores dates as numeric timestamps but better-auth internally expects Date objects, `customTransformOutput` must convert numbers back to Date objects using `new Date(data)`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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.

Type for invitation.expiresAt field is Date, should be number.

1 participant