Build a Subscription App

This guide walks you through a complete subscription integration — from creating plans in the dashboard to gating content based on what the user has purchased. By the end, you'll have a working pricing page, authentication, and access control.


1. Create subscription products

In the tiun.business dashboardarrow-up-right, go to Products and create two subscription products:

  • Light — e.g. EUR 19/month

  • Pro — e.g. EUR 199/month

For each, select Subscription as the pricing type, set the interval to monthly, and configure the fee. Optionally add a trial period. Save and copy both Product IDs.

For more on product configuration, see Productsarrow-up-right. For navigating the dashboard, see Managing Productsarrow-up-right.


2. Install and initialize the SDK

npm install @tiun/sdk
import { tiun } from '@tiun/sdk';

tiun.init({
  snippetId: 'YOUR_SNIPPET_ID',
  language: 'en', // set to your site's language
});

3. Build a pricing page

Create a button for each plan. Each one triggers tiun.checkout() with the corresponding product ID.

When the user clicks, tiun opens the checkout overlay. It collects their email, handles authentication, processes payment, and grants access — all in one flow. There's no separate signup step.


4. Handle checkout success

After a successful purchase, userChange fires with event: 'checkout'. The user object includes their email and the productAccess array with the product they just bought.


5. Gate content based on access

Use the productAccess array to control what the user sees. This handler runs on every user state change — including page load, login, checkout, and logout.

For more on access patterns, see Access Modelarrow-up-right and Protecting Contentarrow-up-right.


6. Add login and logout

For returning users who want to access their account without going through checkout again, add login and logout buttons.

tiun.login() opens a login overlay where the user enters their email and verifies via a phone OTP. After login, userChange fires with event: 'login' and the user's existing productAccess.

tiun.logout() clears the session. userChange fires with event: 'logout' and isAuthenticated: false.

For more on authentication, see Session Modelarrow-up-right.


7. Handle session restore

When a returning user loads your app, tiun restores their session automatically. userChange fires with event: 'init' and their full user state — including productAccess.

You don't need to do anything special for this. The same userChange handler from step 5 handles it. On first load, it fires with the restored state, and your UI updates accordingly.

For more on session persistence, see Subscriptionsarrow-up-right.


8. Go live

Production is the default environment — if you never set sandbox: true, you're already live.

If you've been testing in sandbox:

  1. Remove sandbox: true from your SDK init (or just don't include it)

  2. Use your production product IDs (prefixed with p-live-)

See Sandbox Setuparrow-up-right and Test Flowsarrow-up-right for details on the sandbox environment.


Full example

Here's the complete integration in one place:


For framework-specific implementations, see Reactarrow-up-right, Vuearrow-up-right, and Nuxtarrow-up-right in the SDK reference.

If your backend needs to verify the user's identity before serving protected data, see Verify Subscriptions Server-side.

Last updated

Was this helpful?