Authdog

Fastify

Authentication for Fastify

A tiny, high-performance plugin that validates Authdog sessions on every request and gives you an idiomatic request.authdog context plus a requireAuth guard.

One register call
Register the plugin once and request.authdog is populated on every request. No per-route wiring.
One enforcement point
Add app.authdog.requireAuth as a preHandler and unauthenticated requests are rejected before your handler runs.
No cookie dependency
The plugin parses cookies itself, so you don't need @fastify/cookie to read the session.
Typed by augmentation
request.authdog and app.authdog come with full autocomplete out of the box.

Register the plugin

// server.ts
import { authdogPlugin } from "@authdog/fastify"

await app.register(authdogPlugin, {
  publicKey: process.env.AUTHDOG_PK!,
})

Gate routes with a preHandler

// routes.ts
app.get("/me", {
  preHandler: app.authdog.requireAuth,
}, async (request) => request.authdog!.user)

A plugin, not a framework

Everything Fastify APIs need

A drop-in plugin, a requireAuth guard, and a typed request context, with no assumptions about your stack.

01

Drop-in plugin

app.register(authdogPlugin, { publicKey }) decorates every request with an idiomatic request.authdog context: token, user, and isAuthenticated.

  • One registration
  • Idiomatic request context
02

requireAuth guard

Gate any route with app.authdog.requireAuth as a preHandler. This is the real enforcement point, since request.authdog itself is informational.

  • preHandler guard
  • Rejects before your handler
03

Secure by default

The public key and its identity host are validated once at registration, and tokens are only trusted after the identity host confirms them.

  • Validated at registration
  • Trusted identity host
04

Parses cookies itself

The plugin reads the authdog-session cookie or a Bearer header on its own, so @fastify/cookie isn't required to get started.

  • Cookie or Bearer header
  • No extra plugin needed
05

High performance

A tiny plugin with an option to skip the per-request userinfo call when you validate tokens elsewhere.

  • Minimal overhead
  • Opt out of user lookup
06

Fully typed

request.authdog and app.authdog are typed via module augmentation, so the session context and guard come with full autocomplete.

  • Module augmentation
  • Autocomplete for the guard
01

Install

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

02

Register

await app.register(authdogPlugin, { publicKey }).

03

Gate routes

Add requireAuth as a preHandler where you need it.

Add auth to your Fastify API.

Install the SDK, register the plugin, and gate your routes with requireAuth today. Free to start, with secure defaults built in.