---
title: "@vonvon-kit/astro"
description: "Astro-Integration mit SSR-Middleware, Server-Hilfsfunktionen undIsland-Client-Singleton für statische und serverseitig gerenderteAstro-Seiten."
locale: "de"
---

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

# @vonvon-kit/astro

## Zustand

Registry-Status: UNPUBLISHED. Installieren Sie dieses SDK nur aus einem Checkout des Repository-Quellcodes; verwenden Sie keine externe Paket-Registry.

Paketstatus: **Aktuelles Paket**. Die Astro-Integration,SSR-Middleware, Server-Hilfsfunktionen und Island-Client-Singleton sindimplementiert. Ein echter IdP-Round-Trip auf Produktionsinfrastruktursteht noch manuell aus.

## Integrations-Einrichtung

Registrieren Sie `vonvonIntegration` in `astro.config.mjs`. Die Integration injiziert Server-Middleware mit `addMiddleware` in der Reihenfolge `pre`, hält Verifizierungsmaterial serverseitig und stellt nur die serialisierbare Browsermodus-Konfiguration bereit, die von Client Islands benötigt wird.

```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',
}),
  ],
})
```

## Manuelle 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',
  }),
)
```

## Serverseitige Authentifizierung in .astro-Seiten

```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-Typisierung

Fügen Sie die Typreferenz in `src/env.d.ts` hinzu, um vollständigeTypabdeckung für `Astro.locals.vonvonAuth` zu erhalten.

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

## Exportierte API

| Exportieren | Art | Modul |
| --- | --- | --- |
| `vonvonIntegration` | Astro-Integrationsfabrik | `@vonvon-kit/astro` |
| `createVonvonMiddleware` | Middleware-Factory | `@vonvon-kit/astro` |
| `getAuth, currentUser, vonvonClient` | Server-Hilfsfunktionen | `@vonvon-kit/astro/server` |
| `getClient, initClient, resetClient` | Island-Client-Singleton | `@vonvon-kit/astro/client` |

## Sicherheitshinweise

- `jwtKey` ist ein öffentlicher JWKS-Schlüssel; er eignet sich für dienetzwerklose Prüfung und enthält keinen privaten Schlüssel.
- `secretKey` (`sk_live_xxx`) muss ausschließlich serverseitigbleiben; übergeben Sie ihn nie an eine Island oder ein Client-Bundle.
- Geschützte Routen leiten über `Response.redirect` in der Middlewareweiter, bevor ein Seitenhandler ausgeführt wird; kein clientseitiges JSerforderlich.
- Leitet opaque Core-Cookies nur an einen Session-Token-Endpoint mit exakt gleicher Origin weiter; der Wert wird nie lokal geprüft

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