Skip to content

@vonvon-kit/nextjs

Next.js middleware, App Router and Pages Router server helpers, plus React SDK re-exports.

Middleware

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

vonvonMiddleware() verifies a Bearer or explicit application JWT on the Edge Runtime. For a same-origin Core session, it exchanges the opaque cookie through /v1/sessions/token, verifies the returned JWT, and injects auth state into downstream server request headers.

import { vonvonMiddleware } from '@vonvon-kit/nextjs'

export default vonvonMiddleware({
  jwtKey: JSON.parse(process.env.VONVON_JWKS_PUBLIC_KEY!),
  issuer: 'https://vonvon.id',
  // This same-origin path must be routed to Vonvon Core.
  sessionTokenExchange: { endpoint: '/v1/sessions/token' },
})

export const config = {
  matcher: ['/dashboard(.*)', '/api/protected(.*)'],
}

App Router server helpers

import { auth, currentUser } from '@vonvon-kit/nextjs'

export default async function DashboardPage() {
  const { userId } = await auth()
  if (!userId) return null
  const user = await currentUser()
  return <p>Welcome {user?.email}</p>
}

Pages Router

import { getAuth } from '@vonvon-kit/nextjs'

export const getServerSideProps = async (ctx) => {
  const { userId } = await getAuth(ctx.req)
  if (!userId) return { redirect: { destination: '/sign-in', permanent: false } }
  return { props: {} }
}

Exported API

Export Kind Purpose
vonvonMiddleware function Edge Runtime middleware: verifies JWT, injects auth headers
auth function App Router: returns AuthObject with userId, orgId, orgRole
getAuth function Pages Router: returns AuthObject from IncomingMessage
currentUser function App Router: fetches full user object using server auth context
vonvonClient function Returns server-side VonvonApiClient bound to current request auth
VONVON_AUTH_HEADER string constant Header name for auth state between middleware and server components
VonvonMiddlewareOptions type Options for vonvonMiddleware: jwtKey, issuer, jwtCookieName, sessionTokenExchange, protectedRoutes, publicRoutes
VonvonServerClientOptions type Options for vonvonClient
AuthObject type Authenticated state: userId, orgId, orgRole, sessionId
UnauthenticatedAuthObject type Unauthenticated state with null fields
AuthResult type Union of AuthObject and UnauthenticatedAuthObject
PaginationParams type Cursor and limit params for Management API list calls
PaginatedResponse<T> type Paginated response envelope

Re-exports

  • Re-exports all @vonvon-kit/react client components and hooks via export * from "@vonvon-kit/react".
  • Re-exports from @vonvon-kit/backend: verifyToken, verifyWebhook, authenticateRequest, JwksCache, toVerifyKeySet, AppError, BACKEND_ERROR_CODES, and all their associated types.
  • Server helpers never expose signing secrets to client bundles.
Navigation

Type to search...

Use arrow keys to navigateEnter to selectEscape to close