CIRCLE
Frontend

Vue app

Add sign-in, entitlement checks and a live wallet balance to a Vue 3 app with createAuthPlugin and composables.

The Vue bindings read the session through your backend's /auth routes. They hold no token. You need the Fastify backend (or another bridge) running, with the ai option if you want the wallet and model composables. Requires vue >=3.4.

Install the plugin

import { createApp } from "vue";
import { createAuthPlugin } from "@circle-rd/auth-ai/vue";
import App from "./App.vue";

createApp(App).use(createAuthPlugin()).mount("#app");

createAuthPlugin({ basePath?, auth? }) reads the session once the app runs in a browser (it does nothing without window, so it is safe during server-side rendering). basePath defaults to "/auth".

Sign-in and entitlements

<script setup lang="ts">
import { useAuth, useEntitlements } from "@circle-rd/auth-ai/vue";

const { state, user, login, logout } = useAuth();
const { hasRole, hasFeature } = useEntitlements();
</script>

<template>
  <p v-if="state.status === 'loading'">Loading…</p>
  <button v-else-if="!user" @click="login()">Sign in</button>
  <div v-else>
    <p>Signed in as {{ user.name ?? user.email ?? user.sub }}</p>
    <a v-if="hasRole('admin')" href="/admin">Administration</a>
    <p v-if="hasFeature('beta')">Beta enabled</p>
    <button @click="logout()">Sign out</button>
  </div>
</template>
  • state is a readonly shallowRef of { status, user, error }; user is a computed. Both unwrap in templates.
  • useEntitlements() reads the user at call time, so the checks stay reactive in templates. They improve the interface only: enforce every entitlement on the server.
  • Composables must be called in setup() (or an effect scope) so subscriptions and polling are disposed with the component. Without the plugin they throw Install createAuthPlugin() on the app.

Wallet and models

<script setup lang="ts">
import { useModels, useWallet } from "@circle-rd/auth-ai/vue";
import { formatEuros } from "@circle-rd/auth-ai/client";

const wallet = useWallet({ pollIntervalMs: 15_000 });
const models = useModels();
</script>

<template>
  <p v-if="wallet.state.value.data">
    Balance: {{ formatEuros(wallet.state.value.data.balance) }} €
    <a v-if="!wallet.state.value.data.canSpend" :href="wallet.state.value.data.topupUrl">Top up</a>
  </p>
  <p v-else-if="wallet.state.value.status === 'error'">
    Wallet unavailable ({{ wallet.state.value.error?.code }}).
  </p>
  <ul>
    <li v-for="model in models.state.value.data ?? []" :key="model.id">{{ model.id }}</li>
  </ul>
</template>

Each of useWallet, useWalletStats(days?) and useModels returns { state, refresh } where state is a ref to { status, data, error }; it is not unwrapped at the top level of the returned object, hence .state.value. balance is a bigint of micro-euros: always format it with formatEuros, and decide whether a paid action may start from canSpend. A 401 from one of them refreshes the auth state, so your UI falls back to the sign-in.

For a dev server, proxy /auth and /api to your backend so the cookie stays same-origin: see React app, the setup is identical.

Copyright © 2026