---
title: "@vonvon-kit/astro"
description: "Astro integration with SSR middleware, server helpers, and island client singleton for static and server-rendered Astro sites."
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/astro

## 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 Astro integration, SSR middleware, server helpers, and island client singleton are implemented. A real IdP round-trip on production infrastructure is still pending manual verification.

## Integration setup

Register `vonvonIntegration` in `astro.config.mjs`. The integration injects server middleware with `addMiddleware` at order `pre`, keeps verification material server-side, and exposes only the serializable browser mode configuration required by client islands.

```js
// astro.config.mjs
import { defineConfig } from 'astro/config'
import { vonvonIntegration } from '@vonvon-kit/astro'
import node from '@astrojs/node'

const jwtKeyJson = process.env.VONVON_JWKS_PUBLIC_KEY
if (!jwtKeyJson) throw new Error('Missing VONVON_JWKS_PUBLIC_KEY')

export default defineConfig({
  output: 'server',
  adapter: node({ mode: 'standalone' }),
  integrations: [
vonvonIntegration({
  // This combined SSR setup requires Core routes on the application's exact origin.
  browser: { mode: 'same-origin' },
  jwtKey: JSON.parse(jwtKeyJson),
  issuer: 'https://app.example.com',
  sessionTokenExchange: { endpoint: '/v1/sessions/token' },
  protectedRoutes: ['/dashboard', '/account'],
  signInUrl: '/sign-in',
}),
  ],
})
```

## Manual middleware (alternative)

```ts
// src/middleware.ts
import { sequence } from 'astro:middleware'
import { createVonvonMiddleware } from '@vonvon-kit/astro'

export const onRequest = sequence(
  createVonvonMiddleware({
jwtKey: JSON.parse(import.meta.env.VONVON_JWKS_PUBLIC_KEY),
issuer: 'https://vonvon.id',
sessionTokenExchange: { endpoint: '/v1/sessions/token' },
protectedRoutes: ['/dashboard', '/account'],
signInUrl: '/sign-in',
  }),
)
```

## Server-side auth in .astro pages

```astro
---
// src/pages/dashboard.astro
import { getAuth, currentUser } from '@vonvon-kit/astro/server'

const auth = getAuth(Astro.locals)
if (!auth.userId) return Astro.redirect('/sign-in')

const user = await currentUser(Astro.locals, {
  secretKey: import.meta.env.VONVON_SECRET_KEY,
})
---

<h1>Welcome, {user?.primaryEmailAddress}</h1>
```

## Client island

```tsx
// src/components/SignOutButton.tsx
import { getClient } from '@vonvon-kit/astro/client'

export default function SignOutButton() {
  const client = getClient()

  const handleSignOut = async () => {
const result = await client.signOut()
if (!result.ok) throw new Error(result.error.message)
window.location.href = '/'
  }

  return <button onClick={handleSignOut}>Sign out</button>
}
```

## Astro.locals typing

Add the type reference to `src/env.d.ts` to get full type coverage on `Astro.locals.vonvonAuth`.

```ts
import '@vonvon-kit/astro/locals'
```

## Exported API

| Export | Kind | Module |
| --- | --- | --- |
| `vonvonIntegration` | Astro integration factory | `@vonvon-kit/astro` |
| `createVonvonMiddleware` | middleware factory | `@vonvon-kit/astro` |
| `getAuth, currentUser, vonvonClient` | server helpers | `@vonvon-kit/astro/server` |
| `getClient, initClient, resetClient` | island client singleton | `@vonvon-kit/astro/client` |

## Security notes

- `jwtKey` is a JWKS public key; it is safe for networkless verification and does not contain a private key.
- `secretKey` (`sk_live_xxx`) must stay server-side only; never pass it to an island or client bundle.
- Protected routes redirect via `Response.redirect` in middleware before any page handler runs; no client-side JS is required.
- Forward Core opaque cookies only to an exact same-origin session-token endpoint; the value is never verified locally

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