Skip to content

feat: Add returnUrl parameter to Customer Portal session#66

Open
empz wants to merge 1 commit intoget-convex:mainfrom
empz:customer-portal-return-url
Open

feat: Add returnUrl parameter to Customer Portal session#66
empz wants to merge 1 commit intoget-convex:mainfrom
empz:customer-portal-return-url

Conversation

@empz
Copy link
Copy Markdown

@empz empz commented Apr 8, 2026

Summary

  • Adds an optional returnUrl parameter to createCustomerPortalSession and the generateCustomerPortalUrl action,
    allowing callers to specify where Polar should redirect the customer after they leave the portal.
  • Updates the CustomerPortalLink React component to accept a returnUrl prop, defaulting to window.location.href
    so users are returned to the page they came from.

Changes

  • src/client/index.ts — Accept and forward returnUrl in createCustomerPortalSession and the
    generateCustomerPortalUrl action handler.
  • src/react/index.tsx — Add returnUrl prop to CustomerPortalLink, default to current page URL.
  • tsconfig.json — Add "types": ["node"] so VS Code doesn't complain about process.env.

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

Summary by CodeRabbit

  • New Features
    • Added support for an optional returnUrl parameter in the customer portal flow, allowing users to specify a custom redirect destination after accessing the portal.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Updates add an optional returnUrl parameter to customer portal session creation and URL generation APIs. The React component is enhanced to accept and pass this parameter. TypeScript configuration adds explicit Node.js type environment declaration.

Changes

Cohort / File(s) Summary
API Layer
src/client/index.ts
Added optional returnUrl parameter to createCustomerPortalSession and generateCustomerPortalUrl action, enabling callers to specify a return destination after portal navigation.
React Component
src/react/index.tsx
Extended CustomerPortalLink to accept optional returnUrl prop and pass it through to generateCustomerPortalUrl; updated useEffect dependency list to react to prop changes.
Configuration
tsconfig.json
Added explicit global type environment (compilerOptions.types: ["node"]) and removed trailing whitespace.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With whiskers twitching, I hop with glee,
A returnUrl path, where users can flee!
Portal sessions flow with gentle care,
Back where they came—a rabbit's prayer! 🌿✨

🚥 Pre-merge checks | ✅ 3
✅ 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 accurately summarizes the main change: adding a returnUrl parameter to the Customer Portal session functionality across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/client/index.ts (1)

188-210: ⚠️ Potential issue | 🟡 Minor

The returnUrl parameter is correctly supported by Polar SDK's customerSessionsCreate.

The implementation properly forwards the optional returnUrl to the Polar SDK, which accepts it as an optional absolute URI (1–2083 characters). The portal will display a "Back" button when provided, returning the customer to that URL.

Minor style improvement: returnUrl?: string | undefined is redundant—the ? already indicates the property can be undefined, so use returnUrl?: string instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/client/index.ts` around lines 188 - 210, The createCustomerPortalSession
method currently types the parameter as `{ userId: string, returnUrl?: string |
undefined }`; remove the redundant `| undefined` by changing the param type to
`{ userId: string, returnUrl?: string }` in the createCustomerPortalSession
signature to keep the optional typing concise (update the function declaration
that accepts `userId` and `returnUrl`).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/client/index.ts`:
- Around line 188-210: The createCustomerPortalSession method currently types
the parameter as `{ userId: string, returnUrl?: string | undefined }`; remove
the redundant `| undefined` by changing the param type to `{ userId: string,
returnUrl?: string }` in the createCustomerPortalSession signature to keep the
optional typing concise (update the function declaration that accepts `userId`
and `returnUrl`).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0dfbf27-e346-4db7-88dd-b1e1fb119cd4

📥 Commits

Reviewing files that changed from the base of the PR and between 4014e69 and e949ada.

📒 Files selected for processing (3)
  • src/client/index.ts
  • src/react/index.tsx
  • tsconfig.json

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.

1 participant