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/astro

v0.2.1

Published

Authdog Astro SDK

Readme

@authdog/astro

Authdog Astro SDK for authentication and user management.

Built for Astro's islands model: a framework-agnostic middleware + server helpers handle sessions on the server, and a tiny vanilla client bootstrap handles the login redirect — no UI-framework peer dependency required.

Installation

bun add @authdog/astro

This SDK requires an SSR-capable Astro app (output: "server" or "hybrid") so middleware can read the session cookie per request.

Usage

Middleware

Wire the middleware once so every request gets Astro.locals.authdog:

// 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 }),
);

Augment App.Locals for typed access:

// src/env.d.ts
declare namespace App {
  interface Locals {
    authdog: import("@authdog/astro/server").AuthdogLocals;
  }
}

Server-side (.astro pages, endpoints, actions)

---
import { createAuthdogServer } from "@authdog/astro/server";

const authdog = createAuthdogServer({
  publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY,
});

// From middleware-populated locals:
const isAuthenticated = Astro.locals.authdog?.isAuthenticated;

// Or resolve the full user profile on demand:
const user = await authdog.getUser(Astro.request);
---

{isAuthenticated ? <p>Welcome, {user?.user?.displayName}</p> : <a href="/login">Sign in</a>}

Logout endpoint

// src/pages/api/logout.ts
import type { APIRoute } from "astro";
import { createAuthdogServer } from "@authdog/astro/server";

const authdog = createAuthdogServer({
  publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY,
});

export const GET: APIRoute = ({ request }) => authdog.logout(request);

Client-side bootstrap

<script>
  import { initAuthdog } from "@authdog/astro/client";
  // Consumes ?token=… from the login redirect, persists it, then reloads.
  initAuthdog();
</script>

API Reference

Server

  • authdogMiddleware(config) — Astro middleware that populates Astro.locals.authdog
  • createAuthdogServer(config) — server instance (getSession, getUser, getPublicKey, logout)
  • getSessionCookie(request, cookieName?) — read the raw session token
  • logoutHandler(request, cookieName?) — build a cookie-clearing redirect response
  • getServerSidePayloadPublicKey(publicKey) — validate the public key

Client

  • initAuthdog() — handle the ?token=… login redirect and persist the token
  • clearAuthdogToken() — client-side sign-out (clears localStorage)
  • fetchUserData(publicKey, token) — fetch the user profile from the identity host
  • getTokenFromUri(url), validatePublicKey(publicKey), browserCookiesOptions