---
title: "@vonvon-kit/nuxt"
description: "Nuxt 3 module with H3/Nitro server middleware and auto-imported Vue composables for SSR and full-stack apps."
locale: "en"
---

> Documentation Index
> Fetch the relevant documentation index at: https://vonvon.id/sdks/llms.txt
> Use this file to discover all available pages before exploring further.

# @vonvon-kit/nuxt

## Status

Registry status: UNPUBLISHED. Install this SDK only from the repository source checkout; do not use an external package registry.

Package status is **Current package**. The Nuxt module, H3/Nitro server middleware, and auto-imported composables are implemented. A real IdP round-trip on production infrastructure is still pending manual verification.

## Module setup

Add `@vonvon-kit/nuxt` to the `modules` array. The module auto-imports all [@vonvon-kit/vue](/sdks/vue) composables and registers a client-only plugin that installs `VonvonPlugin`.

```ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vonvon-kit/nuxt'],
  vonvon: {
browser: {
  mode: 'oidc',
  issuer: 'https://vonvon.id',
  clientId: 'client_abc123',
  redirectUri: 'https://app.example.com/auth/callback',
},
  },
})
```

## Composables (auto-imported)

```vue
<script setup lang="ts">
// No import needed -- Nuxt auto-imports from @vonvon-kit/vue
const auth = useAuth()
const userRef = useUser()
const orgRef = useOrganization()
const sessionRef = useSession()
</script>

<template>
  <div v-if="auth.isSignedIn">
Signed in as {{ auth.userId }}
<button @click="auth.signOut()">Sign out</button>
  </div>
</template>
```

## Server middleware (JWT auth)

`createVonvonServerMiddleware` returns an H3 handler that verifies a Bearer or explicit application JWT and writes `event.context.vonvonAuth`. Configure same-origin Core sessions through `sessionTokenExchange`; H3 v1 relative URLs also require a trusted `requestOrigin`. Place the file in `server/middleware/` for global Nitro registration.

```ts
// server/middleware/vonvon.ts
import { createVonvonServerMiddleware } from '@vonvon-kit/nuxt'

export default createVonvonServerMiddleware({
  jwtKey: JSON.parse(process.env.VONVON_JWKS_PUBLIC_KEY!),
  issuer: 'https://acme.vonvon.id',
  sessionTokenExchange: { endpoint: '/v1/sessions/token' },
  requestOrigin: process.env.VONVON_APP_ORIGIN!,
  protectedRoutes: ['/api/admin'],
})
```

## Reading auth in server routes

```ts
// server/routes/api/me.get.ts
import { getVonvonAuth } from '@vonvon-kit/nuxt'

export default defineEventHandler((event) => {
  const auth = getVonvonAuth(event)
  if (!auth.userId) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
  }
  return { userId: auth.userId, orgId: auth.orgId }
})
```

## Exported API

| Export | Kind | Purpose |
| --- | --- | --- |
| `createVonvonServerMiddleware` | function | H3 event handler factory: verifies JWT, writes event.context.vonvonAuth, protects routes |
| `getVonvonAuth` | function | Read AuthResult from event.context.vonvonAuth in server routes and handlers |
| `VONVON_AUTH_CONTEXT_KEY` | string constant | Context key used to store auth result ('vonvonAuth') |
| `VonvonServerMiddlewareOptions` | type | jwtKey, issuer, authorizedParties, jwtCookieName, sessionTokenExchange, requestOrigin, protectedRoutes, onUnauthenticated |

## Security notes

- `event.context.vonvonAuth` is server-side only and is never sent to the browser.
- The middleware strips any client-supplied auth tokens and re-injects only the verified result.
- Place the middleware file in `server/middleware/` to ensure it covers all routes as a global Nitro middleware.

Source: https://vonvon.id/sdks/nuxt/index.mdx
