Time: about 30 minutes · Level: intermediate · You’ll build: a backend route that issues a scoped portal session, and a React page that shows the customer’s plan and balance.
Scenario
Your customers want to check their usage and change plans without emailing you. You’ll give each signed-in customer a short-lived portal session. The browser never sees your API key.Prerequisites
- A sandbox workspace with a
developerAPI key, and a customer such ascust_tutorial_1. - A backend that can keep a secret (Node.js is used here) and a React app.
1
Create a portal session on your backend
Your server checks that the user is signed in to your app, then creates a session for that user’s customer only.
2
Read the portal token in the browser
The React SDK uses the portal token, not your API key. Pass it to The hooks refresh automatically. Show
OrvlinProvider. Use getToken if your token expires, so the SDK can request a new one.loading and error states so the page never looks empty by mistake.3
Let customers preview a plan change
Before a customer changes plans, show what it will cost. The preview doesn’t change anything.Show the result on screen. When the customer confirms, call
POST /v1/portal/plan-change with the same plan.4
Show invoices
5
Expire and revoke access
Sessions expire on their own. Keep
expiresInSeconds short, and create a new session each time the customer opens the billing page. Tokens are scoped to one customer, so a leaked token can’t read another customer’s data.Production checklist
- Create sessions only for users who are signed in to your app.
- Derive the customer ID on the server, never from the request.
- Keep sessions short-lived.
- Enable
allowCreditPurchasesonly if you have credit types configured. - Show the plan-change preview before every change.
Next steps
Customer portal guide
Every portal endpoint and option.
Portal API reference
Request and response details.