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
ready
—
Snippet has initialized and is ready to use.
userChange
{ event: string, isAuthenticated: boolean, user: UserInfo | null }
The user or their access changed (init, login, logout, access, profile).
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.
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 whenever the user or their access changes — session restore, login, logout, a purchase, access that ends, and profile changes. This is the main event for keeping your app in sync with the user's state.
Re-check access every time it fires. Read user.productAccess for subscriptions and one-time products. For a repeatable product, call tiun.checkProductAccess(productId, { referenceId }), or tiun.listProductAccess() for a "My purchases" list:
data.event
Meaning
'init'
First state after the snippet loads, including a restored session.
'login'
The user signed in.
'logout'
The user signed out. user is null.
'checkout'
The user's access changed — gained or lost, for any product type.
'update'
Profile details changed, such as the email or newsletter opt-in.
For 'checkout', that includes:
a purchase or a subscription that ends,
a repeatable product bought with a new reference ID,
access that changed in another tab, once the user comes back to this one.
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.
Errors from the product methods don't fire this event. They only reject the method's Promise, so handle them with try / catch where you call the method.
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?

