> For the complete documentation index, see [llms.txt](https://docs.tiun.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tiun.io/reference/checkout/product-access.md).

# Product access

For subscriptions and one-time purchases alike, the **`productAccess`** array on the user object is the source of truth for **what a user can use right now**. Your application gates features and content by checking whether a product ID appears in that array.

***

## What it contains

`productAccess` is an array of **product IDs** — strings like `p-live-pro` for live products or `p-test-abc123` for sandbox products. IDs always belong to the environment your SDK is using; live and sandbox catalogs are independent. Each ID corresponds to a product the user **currently has access to** — an active subscription, or a one-time purchase they've completed. The array can hold zero, one, or many IDs depending on what the user has purchased.

The full user object that contains this array is documented in [User object](https://docs.tiun.io/reference/authentication/user-object.md).

***

## When it's populated and updated

| When                                  | What happens                                                                                                                                                                                                                                                                                                                            |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| After successful checkout             | The purchased product ID is added to `productAccess`. `userChange` fires with `event: 'checkout'`.                                                                                                                                                                                                                                      |
| On session restore                    | tiun rebuilds `productAccess` for the returning user. `userChange` fires with `event: 'init'`.                                                                                                                                                                                                                                          |
| After login                           | `productAccess` reflects whatever the user is entitled to. `userChange` fires with `event: 'login'`.                                                                                                                                                                                                                                    |
| When a **subscription** ends          | The product ID is **removed** from `productAccess`. The customer should lose access at that moment. A cancelled subscription ends at the end of its paid period.                                                                                                                                                                        |
| For a **one-time purchase**           | The product ID is added at checkout. It stays there permanently, unless the product has **limited access** — then it's removed when the purchase reaches its end date.                                                                                                                                                                  |
| For a **repeatable** one-time product | The product ID shows up in `productAccess` after the first reference and stays until the last one ends, and it never names which reference was bought. Each new reference still fires `userChange` with `event: 'checkout'`. To check one reference, see [Checking access with the SDK methods](#checking-access-with-the-sdk-methods). |
| After logout                          | The user object becomes `null`; there is no `productAccess` to check.                                                                                                                                                                                                                                                                   |
| In another tab                        | When access changes in another tab, `userChange` fires with `event: 'checkout'` once the user comes back to this one.                                                                                                                                                                                                                   |

Re-check access on every `userChange` to keep your UI in sync.

You don't manage renewals yourself — for subscriptions, tiun handles billing cycles and keeps `productAccess` consistent with what the customer has paid for. See [Subscriptions](https://docs.tiun.io/reference/checkout/subscriptions.md) and [One-time purchases](https://docs.tiun.io/reference/checkout/one-time-purchases.md) for the full lifecycle of each.

***

## Checking access

Read `productAccess` from the `userChange` payload (preferred) or via `tiun.user`:

```javascript
tiun.on('userChange', (data) => {
  if (!data.isAuthenticated) return;

  const hasPro = data.user.productAccess.includes('p-live-pro');
  const hasLight = data.user.productAccess.includes('p-live-light');

  if (hasPro) {
    renderProExperience();
  } else if (hasLight) {
    renderLightExperience();
  }
});
```

Replace the example IDs with the product IDs from your [my.tiun.business dashboard](https://my.tiun.business/). For the broader UI gating pattern that combines this with `isAuthenticated`, see [Protecting content](https://docs.tiun.io/reference/authentication/protecting-content.md).

Your backend can also read `productAccess` for any user by their userId — without the user being present — via the UserInfo API. See [getting user info server-side](https://docs.tiun.io/guides/authentication/get-user-info.md). To be told when a user's access changes, subscribe to the `product_access.add` and `product_access.remove` [webhook events](https://docs.tiun.io/reference/webhooks/events.md).

{% hint style="info" %}
Prefer `userChange` over polling `tiun.user`. The event fires precisely when access changes, so your gates stay in sync without manual refresh logic.
{% endhint %}

***

## Checking access with the SDK methods

`productAccess` only holds product IDs. When you need more — which reference ID a repeatable product was bought for, when access started, or when it ends — ask tiun directly from the browser. Needs `@tiun/sdk` 0.12.0 or later (`@tiun/react-native-sdk` 0.5.0 in React Native, on `useTiun()`).

| Method                                                | Returns                                                                                                                                                   |
| ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tiun.listProductAccess()`                            | Every active product access of the current user: `productId`, `referenceId`, `type`, `activatedAt`, `expiresAt`. `[]` when logged out.                    |
| `tiun.checkProductAccess(productId, { referenceId })` | `{ hasAccess, access }` for one product, or one purchase of a repeatable product. `{ hasAccess: false, access: null }` when logged out or without access. |

```javascript
const { hasAccess, access } = await tiun.checkProductAccess('p-live-pro');

if (hasAccess && access.expiresAt) {
  // Cancelled subscription: access ends at the end of the paid period
  showNotice(`Your plan ends on ${new Date(access.expiresAt).toLocaleDateString()}`);
}
```

`expiresAt` is `null` while a subscription is active and renewing, and set to the end of the paid period once it's cancelled. Both methods fetch fresh from the backend, while `productAccess` is the cached copy that `userChange` keeps in sync — use whichever fits. See [Core Methods / Products](https://docs.tiun.io/sdk/web-sdk/core-methods.md#products) for all four product methods and their errors.

{% hint style="info" %}
**Checking on your server instead.** These methods need no backend. If your backend serves the content, check access there with the [UserVerification API](https://docs.tiun.io/api/user-verification.md) or the product access API. See [Protecting content](https://docs.tiun.io/reference/authentication/protecting-content.md).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tiun.io/reference/checkout/product-access.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
