Read customer data and feature access, track usage, checkout, and open customer portal from one hook.
The useCustomer hook fetches customer profile data and feature access in one request. If the customer does not exist yet, PriceOS will create it automatically.
Optional SWR config for caching/revalidation behavior.
Returns
PriceOSCustomer<MyFeatures> | null
Customer data including profile fields and featureAccess.
boolean
Whether data is currently loading.
Error | null
Error from the latest request.
() => Promise<void>
Manually revalidate customer data.
(body) => Promise<TrackUsageResponse>
Tracks usage and revalidates customer and feature-access caches.
(body) => Promise<CreateCheckoutResponse>
Creates a checkout session and redirects to Stripe Checkout.
(body?) => Promise<CreateCustomerPortalResponse>
Creates a customer portal session and redirects to Stripe Customer Portal.
trackUsage body
string
required
Feature key to track usage for (typed to your tracked limit feature keys when using generated types).
number
Usage amount to record. Defaults to 1.
string
Stable event key for retries and deduplication.
number
Unix timestamp in milliseconds for when the event happened.
Record<string, string>
Optional string key/value metadata attached to the usage event.
When using built-in Next.js handlers (priceos/next), client hook calls must use a positive amount.
For negative adjustments, track usage on your backend with the Node.js SDK or REST API.