Browse docs

@kolaylogin/astro

Astro integration middleware. Verifies __session on each request, exposes Astro.locals.auth, and optionally redirects unauthenticated visitors away from protected routes.

Copy this quickstart guide as a prompt for LLMs to implement KolayLogin in your application.

Install

npm install @kolaylogin/astro @kolaylogin/backend

Add the middleware

src/middleware.ts
import { createKolayLoginMiddleware } from '@kolaylogin/astro';

export const onRequest = createKolayLoginMiddleware({
  // baseUrl defaults to https://api.kolaylogin.com
  issuer: import.meta.env.KL_JWT_ISSUER,
  protectedPaths: ['/dashboard(.*)'],
  signInUrl: '/sign-in',
});

Use in pages

src/pages/dashboard/index.astro
---
const auth = Astro.locals.auth;
if (!auth) return Astro.redirect('/sign-in');
---
<h1>Hi {auth.userId}</h1>
<p>Your active org: {auth.orgId ?? 'none'}</p>

API shape on Astro.locals.auth

  • userId, sessionId, environmentId
  • orgId, orgRole (null when no active org)
  • claims — raw verified JWT claims.

Composing with your own middleware? Import sequencefrom the same package — mirrors Astro's own utility.