Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jun 4, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Users are now required to have a verified PayPal email address before proceeding, with a clear message if the email is not verified.
    • Improved error handling during PayPal authorization, with user-friendly error messages displayed via toast notifications.
  • Chores

    • Increased the expiration time for PayPal OAuth state from 2 minutes to 5 minutes, improving reliability for users during authentication.
    • Streamlined click data retrieval for faster lead tracking.

@vercel
Copy link
Contributor

vercel bot commented Jun 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 4, 2025 6:35pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

The changes revise PayPal callback error handling by replacing custom errors with generic ones and redirecting unauthorized users to login. They add explicit PayPal email verification checks and append error messages to redirect URLs. The OAuth user info interface is renamed and simplified, with cache expiration extended. The partner auth component now shows toast errors based on URL query parameters. The lead tracking route simplifies Redis cache retrieval by removing fallback to an older key.

Changes

File(s) Change Summary
apps/web/app/(ee)/api/paypal/callback/route.ts Replaced custom errors with generic ones; redirect to login if no session; added PayPal email verification check; logs errors and appends error query param on redirect.
apps/web/lib/paypal/oauth.ts Renamed UserInfo to PayPalUserInfo; removed verified field; clarified email_verified; extended OAuth state cache expiry from 2 to 5 minutes; updated type assertions.
apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx Added error handling for URL query parameters in PartnerProfileAuth component; displays toast notifications for mapped error codes.
apps/web/app/(ee)/api/track/lead/route.ts Simplified Redis cache retrieval by removing fallback key; fetches only one Redis key for click data.

Possibly related PRs

  • Improve click caches #2470: Simplifies lead tracking route by removing fallback to old Redis key, similar to the current removal of fallback logic in Redis cache retrieval.

Suggested reviewers

  • devkiran

Poem

In the warren of code, a check hops anew,
PayPal emails must be verified, it's true!
With names now tidied and cache time grown,
Errors handled simply, as clearly shown.
🐇✨ Verified bunnies, proceed—unverified, postpone!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c06adcc and 4a20dc7.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/track/lead/route.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
apps/web/app/(ee)/api/track/lead/route.ts (1)

97-99:

Details

✅ Verification successful

Verify cache key migration strategy to prevent data loss.

The simplification from mget with fallback logic to a single get call improves performance, but removing access to the old clickCache:${clickId} key pattern could cause "Click event not found" errors if existing cached entries under that pattern haven't expired yet.

Please verify that this change is coordinated with the caching strategy:


🏁 Script executed:

#!/bin/bash
# Description: Check if there are any references to the old cache key pattern and verify cache write operations
# Expected: Find where clickIdCache keys are written and confirm no existing clickCache keys will be orphaned

echo "=== Searching for cache key patterns ==="
rg -A 3 -B 3 "clickCache:" --type ts
echo ""
echo "=== Searching for clickIdCache write operations ==="
rg -A 5 -B 3 "clickIdCache.*set|set.*clickIdCache" --type ts
echo ""
echo "=== Searching for any mget operations that might have been removed ==="
rg -A 3 -B 3 "mget.*click" --type ts

Length of output: 1311


Cache key migration validated—no orphaned clickCache entries detected.

A search across the codebase shows:

  • No references or writes to the old clickCache:${clickId} pattern.
  • All cache‐write operations use only clickIdCache:${clickId} (e.g. in apps/web/lib/tinybird/record-click.ts).
  • No remaining mget calls for click data.

Removing the fallback to clickCache:${clickId} is safe, as no legacy keys are in use.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

@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)
apps/web/app/(ee)/api/paypal/callback/route.ts (1)

98-101: Consider encoding concerns for error messages in URL.

While the error handling approach is good, be mindful that error messages in URL parameters could potentially expose sensitive information or be logged in access logs.

The current implementation uses encodeURIComponent which is correct, but consider if the error messages contain any sensitive information that shouldn't appear in URLs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb08471 and c06adcc.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/api/paypal/callback/route.ts (4 hunks)
  • apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/app/(ee)/api/paypal/callback/route.ts (1)
packages/utils/src/constants/main.ts (1)
  • PARTNERS_DOMAIN (52-57)
apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx (1)
apps/web/lib/swr/use-partner-profile.ts (1)
  • usePartnerProfile (6-29)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (10)
apps/web/app/(ee)/api/paypal/callback/route.ts (6)

28-30: LGTM: Improved user experience for unauthenticated users.

The change from throwing an error to immediate redirect provides better UX by sending unauthenticated users directly to the login page instead of showing an error.


32-34: Good addition: Local error tracking for URL parameter passing.

The introduction of the error variable and try-catch block properly supports the new error handling approach where errors are passed via URL parameters instead of API responses.


49-49: Consistent error handling approach.

The change to generic Error with "invalid_state" message aligns with the new error handling strategy.


60-62: Excellent security enhancement: PayPal email verification check.

Adding explicit verification of the PayPal email address is a critical security improvement that prevents unverified PayPal accounts from being linked to partner profiles.


90-96: Simplified error handling with proper logging.

The new approach logs errors for debugging while capturing the message for user feedback. This is more appropriate for a redirect-based flow than returning API error responses.


38-38:

Details

✅ Verification successful

Verify error code consistency across components.

The error message "partner_not_found" should match the error codes defined in the auth component.


🏁 Script executed:

#!/bin/bash
# Description: Verify error code consistency between PayPal callback route and auth component
# Expected: Both files should use the same error codes

echo "=== Error codes in PayPal callback route ==="
rg -A 1 -B 1 'throw new Error\(' apps/web/app/\(ee\)/api/paypal/callback/route.ts

echo -e "\n=== Error codes in auth component ==="
rg -A 10 'ERROR_CODES.*=' apps/web/app/\(ee\)/partners.dub.co/\(dashboard\)/auth.tsx

Length of output: 1087


No changes needed—error codes are consistent
The error strings thrown in apps/web/app/(ee)/api/paypal/callback/route.ts
(“partner_not_found”, “invalid_state”, “paypal_email_not_verified”) exactly match the keys in ERROR_CODES in apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx.

apps/web/app/(ee)/partners.dub.co/(dashboard)/auth.tsx (4)

6-8: LGTM: Appropriate imports for error handling functionality.

The added imports support the new error handling feature with URL parameter reading and user notifications.


10-18: Well-structured error code mapping with user-friendly messages.

The ERROR_CODES object provides clear, actionable error messages that guide users on how to resolve issues. The mapping covers all the error scenarios from the PayPal callback route.

Note: The error codes match the ones thrown in the PayPal callback route, ensuring consistency across the error handling flow.


21-21: Proper use of useSearchParams for error handling.

The hook correctly reads URL search parameters to detect errors passed from the callback route.


25-31: Effective error feedback implementation with proper cleanup.

The useEffect properly reads error parameters and displays toast notifications. The fallback error message ensures users always receive feedback even for unexpected error codes.

The implementation correctly depends on searchParams to re-run when URL parameters change.

@steven-tey steven-tey merged commit 24d8213 into main Jun 4, 2025
8 checks passed
@steven-tey steven-tey deleted the paypal-verified branch June 4, 2025 18:41
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