Skip to main content
The customer portal endpoint allows authenticated users to access a billing portal where they can manage their subscription, update payment methods, view invoices, and cancel their subscription.

Endpoint

Authentication

This endpoint requires authentication. The user must have an active session with a valid JWT token.

Request Body

string
Optional URL to redirect the user after they’re done in the portal. Defaults to the dashboard.

Example Request

Response

string
required
The URL to redirect the user to the billing portal

Success Response (200)

Error Responses

Returned when the user is not authenticated.
Returned when no customer record exists for the authenticated user.
Returned when the customer’s payment provider doesn’t match the active provider or invalid request body.
Returned when an unexpected error occurs.

Implementation Details

The endpoint follows this workflow:
  1. Authentication Check - Verifies the user has an active session
  2. Find Customer - Queries the database for the customer record using userId
  3. Provider Validation - Ensures the customer’s provider matches the currently active payment provider
  4. Create Portal Session - Calls the payment adapter’s createPortal() method
  5. Return URL - Returns the portal URL for client-side redirect

Source Code Reference

The implementation can be found in src/app/api/payments/portal/route.ts:

Provider Support

All payment providers implement the createPortal() method:
  • Stripe - Creates a Stripe Billing Portal session
  • Polar - Returns the Polar dashboard URL
  • Lemon Squeezy - Creates a customer portal session

Usage Example

Here’s how to use the portal endpoint in a React component:

Next Steps