Subscriptions

Subscriptions in tiun revolve around an identified user, checkout, and a persistent session. Understanding the journey from anonymous visitor to subscribed customer—and back—helps you place paywalls, login, and logout in the right order.


The journey

  1. A visitor arrives unauthenticated: no tiun session yet.

  2. They may open checkout directly. The checkout overlay collects email and payment; completing it both authenticates the user and grants product access in one step.

  3. Alternatively, they may log in first with tiun.login(), then subscribe later via checkout when they are ready.

  4. A returning user on the same browser gets session restoration automatically; userChange fires with event: 'init' (among other cases) so your UI can sync.

  5. The user may log out; the session is cleared and they are anonymous again until they sign in or complete checkout.

circle-info

Checkout also authenticates the user. If a visitor goes directly to checkout without logging in first, they provide their email during the payment flow and are authenticated automatically.


Flow diagram

Subscription flow: Visitor to Authenticated via login or checkout, with logout path

The top branch shows login first, then optional checkout or logout. The bottom branch shows checkout from cold start, which both subscribes and establishes identity.


Key points

Checkout authenticates automatically. You do not need a separate “sign up” step before payment for the common case: email plus payment in the overlay establishes the account and entitlements together.

productAccess on the user record lists which product IDs the customer can use. Gate features and premium areas by checking this array (and by listening for updates).

userChange is the primary UI sync mechanism: initial load, login, logout, and purchase updates can all surface through it. Build your header, account area, and paywalls around this event so they stay consistent with tiun’s view of the user.

Session persistence means returning users are recognized when they come back; you avoid forcing login on every visit while the session remains valid. Combine that with userChange so the first paint reflects restored state as soon as tiun initializes.


For an end-to-end walkthrough, see Build a subscription apparrow-up-right.

Last updated

Was this helpful?