Skip to content

Fix expiration type#634

Merged
edulelis merged 1 commit intoelie222:stagingfrom
edulelis:migrate-to-better-auth
Aug 5, 2025
Merged

Fix expiration type#634
edulelis merged 1 commit intoelie222:stagingfrom
edulelis:migrate-to-better-auth

Conversation

@edulelis
Copy link
Collaborator

@edulelis edulelis commented Aug 5, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency in how expiration times are handled for Gmail and Outlook integrations, ensuring all expiration values are now passed as numeric timestamps or null.
    • Updated token handling and validation logic to prevent issues related to date formats.
    • Adjusted access token retrieval for sender categorization to support updated session structures.
    • Streamlined account deletion by removing redundant sign-out steps.
  • Refactor

    • Simplified and unified the way expiration and token data are processed across multiple features and integrations.

@vercel
Copy link

vercel bot commented Aug 5, 2025

@edulelis is attempting to deploy a commit to the Inbox Zero OSS Program Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes standardize how expiration dates (expiresAt/expires_at) are handled across various modules. Instead of passing Date objects or potentially undefined values, the code now consistently converts these to numeric timestamps (milliseconds since epoch) or null. Related logic in Gmail and Outlook client utilities is updated to expect and use these numeric values directly, removing previous conversions.

Changes

Cohort / File(s) Change Summary
API Route Expiry Handling (Gmail/Outlook)
apps/web/app/api/ai/analyze-sender-pattern/route.ts, apps/web/app/api/clean/gmail/route.ts, apps/web/app/api/google/watch/all/route.ts, apps/web/app/api/google/webhook/process-history.ts, apps/web/app/api/outlook/watch/all/route.ts, apps/web/app/api/outlook/watch/route.ts, apps/web/app/api/outlook/webhook/process-history.ts, apps/web/app/api/user/categorize/senders/batch/handle-batch.ts, apps/web/utils/api-auth.ts
All usages of account expiration dates now convert Date objects to numeric timestamps (via .getTime()) or pass null, ensuring consistent argument types for downstream client functions.
Google Contacts API
apps/web/app/api/google/contacts/route.ts
Removes the expiryDate property from the configuration object passed to getContactsClient.
Gmail Client Expiry Logic
apps/web/utils/gmail/client.ts
Removes multiplication by 1000 when assigning expiryDate from expiresAt, expecting timestamps in milliseconds directly.
Outlook Client Expiry Logic
apps/web/utils/outlook/client.ts
Removes multiplication by 1000 for expiryDate, using the provided timestamp directly for token validity checks.
Account Utility Expiry Consistency
apps/web/utils/account.ts
Cleans up and standardizes how expiration timestamps are passed to client functions, ensuring .getTime() is used where needed.
Token Structure Normalization
apps/web/utils/user/get.ts
Ensures the tokens object always contains expires_at as a number or null, not a Date object.
Categorize Action Token Access
apps/web/utils/actions/categorize.ts
Changes token retrieval from session.accessToken to session.session.token in categorizeSenderAction.
User Action Auth Cleanup
apps/web/utils/actions/user.ts
Removes redundant auth.api.signOut() call from deleteAccountAction, simplifying the user deletion process.

Sequence Diagram(s)

sequenceDiagram
    participant API_Route as API Route
    participant DB as Database
    participant ClientUtil as Gmail/Outlook Client Utility

    API_Route->>DB: Fetch account (with expires_at)
    DB-->>API_Route: Return account (expires_at as Date or null)
    API_Route->>API_Route: Convert expires_at to timestamp (ms) or null
    API_Route->>ClientUtil: Call client util with expiresAt (number or null)
    ClientUtil->>ClientUtil: Use expiresAt directly for token checks
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A hop and a skip, through code we bound,
Dates to numbers, consistency found.
No more guessing what time means what—
Now timestamps rule, confusion is cut.
Outlook and Gmail, both now in sync,
This bunny approves—let’s pause for a drink! 🥕

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a53fcbe and cdb4ea0.

📒 Files selected for processing (16)
  • apps/web/app/api/ai/analyze-sender-pattern/route.ts (1 hunks)
  • apps/web/app/api/clean/gmail/route.ts (1 hunks)
  • apps/web/app/api/google/contacts/route.ts (0 hunks)
  • apps/web/app/api/google/watch/all/route.ts (1 hunks)
  • apps/web/app/api/google/webhook/process-history.ts (1 hunks)
  • apps/web/app/api/outlook/watch/all/route.ts (1 hunks)
  • apps/web/app/api/outlook/watch/route.ts (1 hunks)
  • apps/web/app/api/outlook/webhook/process-history.ts (1 hunks)
  • apps/web/app/api/user/categorize/senders/batch/handle-batch.ts (1 hunks)
  • apps/web/utils/account.ts (7 hunks)
  • apps/web/utils/actions/categorize.ts (1 hunks)
  • apps/web/utils/actions/user.ts (0 hunks)
  • apps/web/utils/api-auth.ts (1 hunks)
  • apps/web/utils/gmail/client.ts (2 hunks)
  • apps/web/utils/outlook/client.ts (1 hunks)
  • apps/web/utils/user/get.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@edulelis edulelis merged commit 191185c into elie222:staging Aug 5, 2025
4 of 7 checks passed
Copy link

@johnlowe399-blip johnlowe399-blip left a comment

Choose a reason for hiding this comment

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

apps/web/app/api/clean/gmail/route.ts

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.

2 participants

Comments