Authdog

Astro

Authentication for Astro, islands and all

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.

One middleware
Register authdogMiddleware once and Astro.locals.authdog is populated on every request. No per-page setup.
No UI peer dependency
The middleware and vanilla client bootstrap are framework-agnostic, so auth works with any island you render.
Session read per request
The cookie is parsed and verified in middleware before your page renders, so protected content never flashes.
Typed locals
Augment App.Locals once and the session autocompletes across pages, endpoints, and actions.

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

Everything Astro apps need

Server middleware and helpers that resolve sessions per request, with no UI-framework lock-in.

01

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
02

Built for islands

A framework-agnostic middleware plus a tiny vanilla client bootstrap means no UI-framework peer dependency. It works with whatever you render.

  • Zero UI peer dependencies
  • Any island framework
03

Server helpers

createAuthdogServer() resolves the full user on demand in .astro pages, endpoints, and actions, and handles logout from an API route.

  • Pages, endpoints, actions
  • Server-side logout
04

Secure by default

Tokens are validated against the trusted identity host and sessions ride secure, HTTP-only cookies read only on the server.

  • HTTP-only cookies
  • Tokens verified server-side
05

SSR & hybrid ready

Designed for SSR-capable Astro apps so middleware can read the session cookie on every request, with no static-only limitations.

  • SSR and hybrid output
  • Cookie read per request
06

Typed locals

Augment App.Locals once and Astro.locals.authdog is fully typed across your pages, endpoints, and actions.

  • App.Locals augmentation
  • Autocomplete everywhere
01

Install

Add @authdog/astro and your environment's public key.

02

Add middleware

Export authdogMiddleware from src/middleware.ts.

03

Read the session

Branch on Astro.locals.authdog in pages and endpoints.

Add auth to your Astro app.

Install the SDK, wire up the middleware, and read the session from Astro.locals today. Free to start, with secure defaults built in.