Events
Last updated
Was this helpful?
Was this helpful?
tiun.on('ready', () => {
// Safe to call checkout, login, start, etc.
});tiun.on('userChange', (data) => {
// data.event — what triggered the change: 'init', 'login', 'checkout', 'logout', 'update'
// data.isAuthenticated — whether the user has a valid session
// data.user — { userId, email, productAccess } or null
});// Correct — initial state arrives via the listener
tiun.on('userChange', syncStateFromTiun);
tiun.init({ snippetId });tiun.on('login', (data) => {
// data.user — the authenticated user's info
});tiun.on('logout', () => {
// User is logged out
});tiun.on('paywallShow', (data) => {
// data.isConnected — whether the user has a payment method connected
showPaywall();
});tiun.on('paywallHide', (data) => {
// data.sessionId — the active session ID
// data.isConnected — whether the user has a payment method connected
hidePaywall();
});tiun.on('error', (err) => {
// err.code — error code
// err.message — human-readable message
// err.details — optional additional info
});const unsubscribe = tiun.on('userChange', handler);
// Later, to stop listening:
unsubscribe();tiun.once('ready', () => {
console.log('First ready event');
});