Events

Usage

Subscribe to events with tiun.on() to react when something happens in the SDK.

tiun.on('ready', () => {
  console.log('tiun is ready');
});

tiun.on('userChange', (data) => {
  console.log('user state changed:', data.event);
});

Event reference

Event
Payload
Description

ready

Snippet has initialized and is ready to use.

userChange

{ event: string, isAuthenticated: boolean, user: UserInfo | null }

User state changed (init, login, checkout, logout).

login

{ user: UserInfo }

User has logged in.

logout

User has logged out.

paywallShow

{ isConnected: boolean }

Paywall should be shown (user doesn't have access).

paywallHide

{ sessionId: string, isConnected: boolean }

User has access, hide the paywall.

error

{ code: string, message: string, details?: any }

An error occurred.

circle-info

userChange, login, and logout are specific to subscriptions. paywallShow and paywallHide are specific to time-based billing.

ready

Fires once when the snippet has fully loaded and is ready to use. Use this to delay any SDK calls that depend on the snippet being available.

userChange

Fires on every user state change — login, logout, checkout, or session restore. This is the main event for keeping your app in sync with the user's state.

login

Fires when the user has successfully logged in.

logout

Fires when the user session has been cleared.

paywallShow

Fires when the user does not have access and the paywall should be displayed. Use this to show your paywall UI or gate content.

paywallHide

Fires when the user has access and the paywall should be hidden. Use this to reveal content.

error

Fires when an error occurs in the SDK.


Unsubscribing

tiun.on() returns an unsubscribe function. Call it if you need to remove a specific listener — for example, inside a component that mounts and unmounts.

For most integrations where listeners are set up once at app startup, you don't need to unsubscribe manually — tiun.destroy() cleans up everything.


Listening once

Use tiun.once() to listen for an event a single time. The listener is automatically removed after it fires.

Last updated

Was this helpful?