npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@authdog/fastify

v0.3.1

Published

Authdog Fastify SDK

Downloads

295

Readme

@authdog/fastify

Authdog SDK 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 — built on @authdog/node-commons.

  • 🔌 Drop-in pluginapp.register(authdogPlugin, { publicKey }).
  • 🔐 Secure by default — public key (and its identity host) validated once at registration; tokens only trusted after the identity host confirms them.
  • 🧱 No assumptions — parses cookies itself; @fastify/cookie not required.
  • 🟦 Typedrequest.authdog and app.authdog are fully typed via module augmentation.

Install

bun add @authdog/fastify fastify

Set your Authdog public key (safe to expose):

AUTHDOG_PK=pk_xxxxxxxxxxxxxxxx

Usage

import Fastify from "fastify";
import { authdogPlugin } from "@authdog/fastify";

const app = Fastify();

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

// Every request now carries `request.authdog` ({ token, user, isAuthenticated }).
app.get("/", async (request) => {
  return request.authdog?.isAuthenticated
    ? `Hello ${JSON.stringify(request.authdog.user)}`
    : "Not signed in";
});

// Protect a route with the built-in guard (the real enforcement point).
app.get(
  "/me",
  { preHandler: app.authdog.requireAuth },
  async (request) => request.authdog!.user,
);

// Logout: clears the session cookie and redirects to a sanitized ?redirect_uri.
app.get("/logout", (request, reply) => app.authdog.logout(request, reply));

await app.listen({ port: 3000 });

Token resolution

On each request the plugin looks for a token in this order:

  1. The authdog-session cookie.
  2. An Authorization: Bearer <token> header.

If a token is found it is verified against the identity host's userinfo endpoint and, on success, request.authdog.isAuthenticated becomes true and request.authdog.user is populated. A missing or invalid token never throws — it simply yields an unauthenticated context.

Options

| Option | Type | Default | Description | | --------------- | --------- | ------- | --------------------------------------------------------------------------- | | publicKey | string | — | Authdog public key (pk_…). Required. | | secretKey | string | — | Reserved for future server-side session revocation. Currently unused. | | fetchUserInfo | boolean | true | When false, skips the per-request userinfo call (token is not verified). |

⚠️ request.authdog is informational. Always gate protected routes with app.authdog.requireAuth (or your own check on isAuthenticated).

License

MIT