Check an active subscription
Use customers.hasActiveSubscription when every paid plan grants the same top-level access.
const hasPaidAccess = await strent.customers.hasActiveSubscription({ customer: account.stripeCustomerId,});The SDK reads the customer’s active items and returns true when there is at least one. Active items are the prices charged by current Stripe subscriptions (Stripe calls them subscription items) with a status that gives access, and Stripe never leaves a subscription without items:
activetrialingpast_due
It returns false for a customer Strent has read that has no subscription giving access. Canceled and unpaid subscriptions do not grant this fact.
Keep identity and policy in your application
Section titled “Keep identity and policy in your application”Resolve the authenticated user to an application account first, then read the account’s stored Stripe Customer ID:
const account = await accounts.forUser(session.userId);const hasPaidAccess = await strent.customers.hasActiveSubscription({ customer: account.stripeCustomerId,});
if (!account.members.includes(session.userId) || !hasPaidAccess) { throw new ForbiddenError();}Do not accept a caller-supplied stripe_customer_id as proof that the caller owns that customer. Strent reports Stripe facts; your application proves identity, membership, and resource ownership.
Not ready is not false
Section titled “Not ready is not false”When Strent has not read the customer from Stripe yet, the API returns 409 CUSTOMER_STATE_NOT_READY and the SDK throws StrentApiError. A customer you just created is in this state for a few seconds. If your app may check access in those seconds, call strent.customers.refresh({ customer }) right after creating the Stripe customer. Either way, define the failure behavior before using this check on a request path.