Nuxt API reference
Every export is fully typed. The signatures and props below come from the package's own reference documentation, so what is listed here is what the installed version ships.
Composables
useThunderID()
hook
The useChoreo Identity & Access Management composable provides access to the Choreo Identity & Access Management authentication context in Nuxt applications. It exposes reactive auth state and SSR-safe methods for signing in, signing out, and signing up. This composable is auto-imported and available in every component, page, and composable without an explicit import.
Returns
| Name | Type | Description |
|---|---|---|
| isSignedIn | ComputedRef | Whether the user is currently authenticated |
| isLoading | ComputedRef | Whether an auth operation is in progress |
| isInitialized | ComputedRef | Whether the SDK has finished initializing |
| user | ComputedRef<User \ | The authenticated user object, or null if not signed in |
| organization | ComputedRef<Organization \ | The current organization context, or null |
| signIn | (...args) => Promise | Initiate the sign-in flow |
| signOut | () => Promise | Sign out the current user |
| signUp | (...args) => Promise | Initiate the sign-up flow |
| getAccessToken | () => Promise | Get a client-safe access token via /api/auth/token |
<script setup lang="ts">
const { isSignedIn, user, signIn, signOut } = useThunderID()
</script>
<template>
<div>
<p v-if="isSignedIn">Welcome, {{ user?.displayName }}!</p>
<button v-if="isSignedIn" @click="signOut()">Sign Out</button>
<button v-else @click="signIn()">Sign In</button>
</div>
</template>
useUser()
hook
The useUser composable returns the currently authenticated user object as a reactive computed ref. It is auto-imported and available everywhere without an explicit import.
<script setup lang="ts">
const user = useUser()
</script>
<template>
<div v-if="user">
<h1>{{ user.displayName }}</h1>
<p>{{ user.email }}</p>
</div>
<p v-else>Not signed in.</p>
</template>
Components
ChangeCredential /
component
The ChangeCredential component renders a form that lets a signed-in user set a new value for one of their own credentials. It collects only a new value and its confirmation, checks it against the applicable rules as the user types, and posts the change through the Nuxt server route to Choreo Identity & Access Management. It is auto-registered by the Nuxt module. It reads the rules it needs from the user type schema already resolved by ThunderIDRoot (GET /users/me/meta), so it adds no network request beyond the write itself. Every default label, placeholder, and message is built from the credential attribute's own displayName in that schema, so it always matches whatever an admin named it there. By default it manages the password credential. To manage a different one, for example a PIN declared on the user type schema, set attribute; render the component once per credential to let a user manage more than one.
ChangeCredential collects only a new value and its confirmation, not the account's existing value. The self-service credential write path does not verify the current value today, so asking for one would only teach the user a false sense of security. Once server-side current-value verification ships, that field returns without a breaking change to this component's public props.
Props
| Name | Type | Description |
|---|---|---|
| attribute (optional) | string | The credential attribute this instance manages, any attribute the user type schema declares credential: true for. Defaults to 'password'. |
| cardLayout (optional) | boolean | Whether to wrap the form in a bordered card. Defaults to false. |
| className (optional) | string | Additional CSS class added to the root element. Defaults to ''. |
| policy (optional) | PasswordPolicy | The rules the new value must satisfy. Defaults to the applicable rules from the user type schema. |
| preferences (optional) | Preferences | Component-level preference overrides, including i18n. |
| showRequirements (optional) | boolean | Whether to render the live requirement checklist. Defaults to true. |
| title (optional) | string | Overrides the default "Change {credential}" heading. Pass an empty string to omit the heading entirely. Defaults to a translated, schema-derived heading. |
<template>
<div>
<h2>Security</h2>
<ChangeCredential />
</div>
</template>
Loading /
component
The Loading component renders its default slot while the authentication state is being resolved. It is useful for showing skeleton screens or spinners during the initial hydration phase.
<template>
<Loading>
<p>Loading...</p>
</Loading>
<SignedIn>
<p>Welcome back!</p>
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</template>
SignInButton /
component
The SignInButton component initiates the sign-in flow when clicked. It is auto-registered by the Nuxt module and requires no imports.
Props
| Name | Type | Description |
|---|---|---|
| preferences (optional) | Preferences | Customization options for i18n and theming |
<template>
<SignInButton />
</template>
SignOutButton /
component
The SignOutButton component signs out the current user when clicked. It is auto-registered by the Nuxt module and requires no imports.
Props
| Name | Type | Description |
|---|---|---|
| preferences (optional) | Preferences | Customization options for i18n and theming |
<template>
<SignOutButton />
</template>
SignUpButton /
component
The SignUpButton component initiates the sign-up flow when clicked. It is auto-registered by the Nuxt module and requires no imports.
Props
| Name | Type | Description |
|---|---|---|
| preferences (optional) | Preferences | Customization options for i18n and theming |
<template>
<SignUpButton />
</template>
SignedIn /
component
The SignedIn component renders its default slot only when the user is authenticated. It is the Vue equivalent of the React `` component and is auto-registered by the Nuxt module.
<template>
<SignedIn>
<p>Welcome! You are signed in.</p>
</SignedIn>
</template>
SignedOut /
component
The SignedOut component renders its default slot only when the user is not authenticated. It is auto-registered by the Nuxt module.
<template>
<SignedOut>
<SignInButton />
</SignedOut>
</template>
ThunderIDRoot /
component
The Choreo Identity & Access ManagementRoot component is the root provider for the Choreo Identity & Access Management Nuxt SDK. It mounts the full provider tree, including i18n, branding, theme, flow, user, and organization, and must wrap all content that uses Choreo Identity & Access Management composables or components.
<template>
<ThunderIDRoot>
<NuxtPage />
</ThunderIDRoot>
</template>
User /
component
The User component provides access to the authenticated user object via a scoped slot. It is auto-registered by the Nuxt module.
<template>
<User>
<template #default="{ user }">
<div v-if="user">
<h1>Welcome, {{ user.displayName }}!</h1>
<p>{{ user.email }}</p>
</div>
</template>
</User>
</template>
UserDropdown /
component
The UserDropdown component renders a button showing the user's avatar or name. When clicked, it opens a dropdown menu with links to the user profile and a sign-out action. It is auto-registered by the Nuxt module.
Props
| Name | Type | Description |
|---|---|---|
| appearance (optional) | Appearance | Customize the component's visual appearance |
| preferences (optional) | Preferences | Customization options for i18n and theming |
<template>
<nav>
<SignedIn>
<UserDropdown />
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</nav>
</template>
UserProfile /
component
The UserProfile component renders a full profile management interface. Users can view and edit their personal information, change their password, and manage linked accounts. It is auto-registered by the Nuxt module.
Props
| Name | Type | Description |
|---|---|---|
| appearance (optional) | Appearance | Customize the component's visual appearance |
| sections (optional) | string[] | Restrict which profile sections are shown. Defaults to all sections |
| preferences (optional) | Preferences | Customization options for i18n and theming |
<template>
<UserProfile />
</template>
Middleware
defineThunderIDMiddleware()
middleware
defineThunderIDMiddleware is a factory function that returns a Nuxt route middleware. It handles authentication guards and scope checks, and redirects unauthenticated users. The module also registers a named 'auth' middleware that you can apply to any page using definePageMeta. It uses defineThunderIDMiddleware with its default options.
Options
| Name | Type | Description |
|---|---|---|
| redirectTo | string | Where to redirect unauthenticated (or unauthorized) users |
| requireScopes | string[] | One or more OIDC scopes that must be present in the user's session |
<script setup lang="ts">
definePageMeta({ middleware: 'auth' })
</script>
<template>
<h1>Dashboard</h1>
</template>
Utilities
createRouteMatcher()
function
createRouteMatcher takes an array of route patterns and returns a predicate function. Call the predicate with a path string to check whether it matches any of the patterns. It is primarily used in global middleware to apply auth guards to a set of routes without adding definePageMeta to every page.
import { defineThunderIDMiddleware } from '@thunderid/nuxt'
import { createRouteMatcher } from '@thunderid/nuxt/utils'
const isProtected = createRouteMatcher([
'/dashboard',
'/dashboard/**',
'/account/**',
'/settings/**',
])
export default defineNuxtRouteMiddleware((to) => {
if (isProtected(to.path)) {
return defineThunderIDMiddleware()
}
})
Configuration
Module Configuration
export
The @thunderid/nuxt module is configured via the thunderid key in nuxt.config.ts. The configuration covers credentials, redirect URLs, session handling, and UI preferences.
export default defineNuxtConfig({
modules: ['@thunderid/nuxt'],
thunderid: {
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
baseUrl: 'https://<DATA_PLANE_URL>',
afterSignInUrl: '/dashboard',
afterSignOutUrl: '/',
scopes: ['openid', 'profile', 'internal_login'],
preferences: {
theme: {
inheritFromBranding: true,
mode: 'system',
},
},
},
})
Errors
ThunderIDError
export
Choreo Identity & Access ManagementError is the structured error class thrown by the Choreo Identity & Access Management Nuxt SDK. It extends Error and carries a typed ErrorCode, an optional HTTP status code, an optional cause, and optional context metadata.
import { ThunderIDError, ErrorCode } from '@thunderid/nuxt/errors'
import { getValidAccessToken } from '@thunderid/nuxt/server'
export default defineEventHandler(async (event) => {
try {
const token = await getValidAccessToken(event)
return await $fetch('/api/resource', {
headers: { Authorization: `Bearer ${token}` },
})
} catch (err) {
if (err instanceof ThunderIDError) {
if (err.code === ErrorCode.SessionExpired) {
throw createError({ statusCode: 401, statusMessage: 'Session expired' })
}
if (err.code === ErrorCode.TokenRefreshFailed) {
throw createError({ statusCode: 401, statusMessage: 'Could not refresh token' })
}
}
throw err
}
})
Server
getThunderIDContext()
export
getChoreo Identity & Access ManagementContext returns the Choreo Identity & Access Management context object that the SDK's server plugin attaches to each H3 event during SSR. This gives synchronous access to the session and pre-fetched SSR data without an additional async call.
import { getThunderIDContext } from '@thunderid/nuxt/server'
export default defineEventHandler((event) => {
const ctx = getThunderIDContext(event)
return {
isSignedIn: ctx?.isSignedIn ?? false,
sub: ctx?.session?.sub ?? null,
}
})
getValidAccessToken()
export
getValidAccessToken returns a valid access token for the current session. If the stored access token is expired or about to expire, it automatically uses the refresh token to obtain a new one and updates the session cookie.
import { getValidAccessToken } from '@thunderid/nuxt/server'
export default defineEventHandler(async (event) => {
const accessToken = await getValidAccessToken(event)
const result = await $fetch('https://api.example.com/data', {
headers: { Authorization: `Bearer ${accessToken}` },
})
return result
})
requireServerSession()
export
requireServerSession reads the Choreo Identity & Access Management session from the current H3 event and returns the decoded Choreo Identity & Access ManagementSessionPayload. If no valid session exists, it throws an H3 error with status code 401.
import { requireServerSession } from '@thunderid/nuxt/server'
export default defineEventHandler(async (event) => {
const session = await requireServerSession(event)
// session is guaranteed to be defined here
return { sub: session.sub }
})
useServerSession()
export
useServerSession reads the Choreo Identity & Access Management session from the current H3 event and returns the decoded Choreo Identity & Access ManagementSessionPayload, or null if no valid session exists.
import { useServerSession } from '@thunderid/nuxt/server'
export default defineEventHandler(async (event) => {
const session = await useServerSession(event)
if (!session) {
throw createError({ statusCode: 401, statusMessage: 'Unauthorized' })
}
return { sub: session.sub, scopes: session.scopes }
})
Was this page helpful?