Skip to content

Astro adapter

Install

Terminal window
pnpm add @vendidit/auth-client astro

Middleware

src/middleware.ts
import { defineMiddleware } from 'astro:middleware';
import { createAuthMiddleware } from '@vendidit/auth-client/astro';
export const onRequest = defineMiddleware(
createAuthMiddleware({
apiBaseUrl: import.meta.env.VENDIDIT_AUTH_URL,
appCode: 'marketplace-buyer',
cookieName: 'vauth',
}),
);

This populates Astro.locals.auth for every request with { user, isAuthenticated, principal } — extracted from the bearer or HttpOnly cookie.

Use in pages

---
const { auth } = Astro.locals;
if (!auth.isAuthenticated) {
return Astro.redirect('/login');
}
---
<h1>Welcome, {auth.user.first_name}</h1>

Client-side islands

Astro islands can use the Preact or React adapters directly — just import from @vendidit/auth-client/preact (or /react) inside the island component. The middleware-set cookie is read by the SDK’s bootstrap automatically.