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

@cirodam/auth-core

v0.1.2

Published

Shared session/auth/user-management core for cirodam's self-hosted SvelteKit + Postgres + Drizzle apps

Readme

@cirodam/auth-core

Shared session/auth/user-management core for cirodam's small self-hosted SvelteKit + Postgres + Drizzle apps (tylerdteague_v2, Mirror, SimpleBlog), extracted after noticing password.ts/rateLimit.ts were byte-identical copy-pasted across all three, auth.ts/users.ts were ~90% identical, and security hardening applied to one app (a shorter session lifetime, invalidating other sessions on password change) never reached the others.

What's here

  • @cirodam/auth-core — hashPassword/verifyPassword/getDummyPasswordHash (scrypt-based, with a timing-attack mitigation for unknown usernames), checkRateLimit (in-memory fixed-window limiter), requireUser/requireAdmin (role guards, generic over { role: string }), session management (generateSessionToken, createSession, validateSessionToken, invalidateSession, invalidateOtherSessions, cookie helpers), user CRUD (createUser, listUsers, getUserById, getUserByUsername, verifyUserPassword, updateUsername, updateUserProfile, updateUserPassword, setUserStatusUnlessLastAdmin, deleteUserUnlessLastAdmin), and createAuthHandle — a Handle factory for hooks.server.ts that does setup-gating, session validation/renewal, route-level auth gating (via a publicRoutes allowlist or predicate), and security headers.
  • @cirodam/auth-core/schema — the users/sessions Drizzle pgTable/pgEnum definitions (uuid primary keys, nullable email/firstName/lastName so apps that don't use them just never populate them, 3-value status enum including banned) plus inferred types (User, PublicUser, Session, UserRole, UserStatus).

What's deliberately not here

App-specific policy: which routes are public (that's a config value you pass in, not something this package decides), self-service signup (only one of the three apps has this concept), CSP/analytics/anything unrelated to auth, and app-specific color/UI (see @cirodam/ui-tokens for that).

Using it in a consuming app

npm install @cirodam/auth-core

Your app's src/lib/server/db/schema.ts:

export * from '@cirodam/auth-core/schema';
// ...your own app-specific tables below

Your app's src/app.d.ts:

declare global {
	namespace App {
		interface Locals {
			user: import('@cirodam/auth-core').PublicUser | null;
		}
	}
}

Your app's src/hooks.server.ts:

import { createAuthHandle } from '@cirodam/auth-core';
import { db } from '$lib/server/db';

export const handle = createAuthHandle({
	db,
	publicRoutes: ['/login'], // or a (pathname: string) => boolean predicate
	session: { lifetimeMs: 1000 * 60 * 60, renewalThresholdMs: 1000 * 60 * 30 }
});

Route files call the exported functions directly, threading db and (where lifetime matters) your app's SessionConfig through explicitly — see createSession/validateSessionToken's signatures. There's no hidden module-level db singleton inside this package.

Developing

  • npm run check — tsc --noEmit
  • npm run test — unit tests for the pure-logic modules (password.ts, rateLimit.ts). No DB-integration tests live here — the three consuming apps' own integration suites are the real correctness signal for the DB-touching code.
  • npm run build — emits dist/ via tsc

To develop against a real consuming app before publishing a new version, npm pack here and install the resulting tarball in the app ("@cirodam/auth-core": "file:../auth-core/cirodam-auth-core-x.y.z.tgz") — prefer this over a plain file:../auth-core link, since a file:-linked directory keeps its own local node_modules (needed to build/typecheck this package standalone), which can shadow the consuming app's own drizzle-orm/ @sveltejs/kit peer install during local type-checking in a way a real tarball or registry install never does (only dist/ and package.json are ever published — node_modules isn't part of the package either way).

Publishing

npm run build
npm publish --access public

Bump version in package.json first (semver — this is consumed by multiple apps, so a breaking change to a function's signature or the users/sessions schema shape should be a major bump).