For the complete documentation index, see llms.txt. This page is also available as Markdown.

Nuxt (SSR)

Since Nuxt renders pages on the server first, the tiun SDK must only initialize on the client. The recommended approach is to set up everything in your app.vue using onMounted.

For plain Vue 3 (no SSR), see the Vue example.


Initialize

Initialize tiun inside onMounted in your app.vue. The SDK is idempotent — calling init again on an initialized instance merges config rather than re-initializing — so no guard is needed.

<!-- app.vue -->
<script setup>
import { tiun } from '@tiun/sdk';
import { onMounted } from 'vue';

onMounted(() => {
  tiun.init({
    snippetId: 'YOUR_SNIPPET_ID',
    language: 'en', // 'en' | 'de' | 'fr'
  });
});
</script>

<template>
  <NuxtPage />
</template>

You don't need to call tiun.destroy() from app.vue — the root only unmounts when the page is gone. See Lifecycle and destroy() for the full matrix.


Checkout

Trigger checkout from any component. The SDK is already initialized in app.vue, so you can call methods directly.


Shared state with useState

Use Nuxt's useState to create reactive state that any component can read. This is SSR-safe and works across the app without prop drilling.

Any component can then read the shared state:


Gate content

Use useState values in any page or component to show or hide content based on productAccess.


Paywall events (time-based)

For time-based billing, use paywallShow and paywallHide to control access. Wire them to shared state in app.vue.

Then in any component:


Content management (time-based)

Track route changes to keep billing accurate. Use router.afterEach with an import.meta.client guard so it only runs in the browser. Send the initial content state when the SDK is ready.


Alternative: plugin approach

Instead of app.vue, you can initialize tiun in a Nuxt plugin. The .client.ts suffix ensures it only runs in the browser.

This runs before any component mounts. Either approach works — pick whichever fits your project layout. Neither needs an explicit teardown at the app root.

Last updated

Was this helpful?