Session middleware
Wire authdogMiddleware once and every request gets Astro.locals.authdog: a typed session resolved on the server, per request.
- One registration
- Resolved per request
Astro
Add auth with session middleware, server helpers, and a tiny vanilla client bootstrap. No UI-framework peer dependency required: Authdog fits Astro's islands model instead of fighting it.
Session middleware
// src/middleware.ts
import { defineMiddleware } from "astro:middleware"
import { authdogMiddleware } from "@authdog/astro/server"
export const onRequest = defineMiddleware(
authdogMiddleware({ publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY }),
)
Read the session in .astro
---
// dashboard.astro
const { isAuthenticated } = Astro.locals.authdog
---
{isAuthenticated ? (
<p>Welcome back</p>
) : (
<a href="/login">Sign in</a>
)}
Built for the islands model
Server middleware and helpers that resolve sessions per request, with no UI-framework lock-in.
Wire authdogMiddleware once and every request gets Astro.locals.authdog: a typed session resolved on the server, per request.
A framework-agnostic middleware plus a tiny vanilla client bootstrap means no UI-framework peer dependency. It works with whatever you render.
createAuthdogServer() resolves the full user on demand in .astro pages, endpoints, and actions, and handles logout from an API route.
Tokens are validated against the trusted identity host and sessions ride secure, HTTP-only cookies read only on the server.
Designed for SSR-capable Astro apps so middleware can read the session cookie on every request, with no static-only limitations.
Augment App.Locals once and Astro.locals.authdog is fully typed across your pages, endpoints, and actions.
Add @authdog/astro and your environment's public key.
Export authdogMiddleware from src/middleware.ts.
Branch on Astro.locals.authdog in pages and endpoints.
Install the SDK, wire up the middleware, and read the session from Astro.locals today. Free to start, with secure defaults built in.