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

v0.2.1

Published

Authdog SvelteKit SDK

Downloads

91

Readme

@authdog/sveltekit

Authdog SvelteKit SDK for authentication and user management.

Built for SvelteKit's server model: a handle hook + framework-agnostic server helpers manage sessions on the server, and a tiny vanilla client bootstrap handles the login redirect — no UI peer dependency beyond SvelteKit itself.

Installation

bun add @authdog/sveltekit

Usage

Server hook

Wire the hook once so every request gets event.locals.authdog:

// src/hooks.server.ts
import { createAuthdogHandle } from "@authdog/sveltekit/server";

export const handle = createAuthdogHandle({
  publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY,
});

Composing with other hooks? Use sequence:

import { sequence } from "@sveltejs/kit/hooks";
import { createAuthdogHandle } from "@authdog/sveltekit/server";

export const handle = sequence(
  createAuthdogHandle({ publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY }),
  myOtherHandle,
);

Augment App.Locals for typed access:

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

export {};

Server-side (load, actions, +server.ts)

// src/routes/profile/+page.server.ts
import { createAuthdogServer } from "@authdog/sveltekit/server";
import type { PageServerLoad } from "./$types";

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

export const load: PageServerLoad = async ({ request, locals }) => {
  const user = locals.authdog.isAuthenticated
    ? await authdog.getUser(request).catch(() => null)
    : null;

  return { user: user?.user ?? null };
};

Logout endpoint

// src/routes/logout/+server.ts
import { createAuthdogServer } from "@authdog/sveltekit/server";
import type { RequestHandler } from "./$types";

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

// Clears the session cookie and redirects (honors a sanitized ?redirect_uri).
export const GET: RequestHandler = ({ request }) => authdog.logout(request);

Client-side bootstrap

<!-- src/routes/+layout.svelte -->
<script>
  import { onMount } from "svelte";
  import { initAuthdog } from "@authdog/sveltekit/client";

  // Consume ?token=… from the login redirect, persist it, then reload.
  onMount(() => initAuthdog());
</script>

API Reference

Server

  • createAuthdogHandle(config) — SvelteKit handle hook that populates event.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