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

@ngriffin_uk/auth-core

v0.5.1

Published

Runtime-neutral authentication context and storage contracts

Readme

@ngriffin_uk/auth-core

Backend configuration, sessions, opaque challenges, and typed authentication middleware. The package has no database, cookie, or framework dependency.

pnpm add @ngriffin_uk/auth-core
import { createAuth } from "@ngriffin_uk/auth-core";

const auth = createAuth({
  users,
  sessions,
  challenges,
  identities,
  sessionTtlMs: 30 * 24 * 60 * 60 * 1000,
});

const configured = auth.use(providerMiddleware);

This is for the basic implementation only, see the below section for more information on how to implement the stores and middleware.

Implement the stores

auth-core owns the authentication flow, but not persistence. Adapt your database repositories to its store interfaces:

import {
  createEncryptedChallengeStore,
  createAuth,
  type AuthUser,
  type ChallengeStore,
  type IdentityStore,
  type SessionStore,
  type UserStore,
} from "@ngriffin_uk/auth-core";

interface AppUser extends AuthUser {
  readonly displayName: string;
}

const users: UserStore<AppUser> = {
  findById: (userId) => userRepository.findById(userId),
};

const sessions: SessionStore = {
  create: (record) => sessionRepository.insert(record),
  findByTokenHash: (tokenHash) =>
    sessionRepository.findByTokenHash(tokenHash),
  deleteByTokenHash: (tokenHash) =>
    sessionRepository.deleteByTokenHash(tokenHash),
  rotateByTokenHash: (tokenHash, replacement) =>
    sessionRepository.rotateByTokenHash(tokenHash, replacement),
  touchByTokenHash: (tokenHash, expiresAt) =>
    sessionRepository.touchByTokenHash(tokenHash, expiresAt),
  deleteByUserId: (userId) =>
    sessionRepository.deleteByUserId(userId),
};

const persistedChallenges: ChallengeStore = {
  async create(record) {
    await challengeRepository.insert(record);
  },
  async consumeByTokenHash(tokenHash) {
    // This must atomically delete and return the row so a token cannot be reused.
    return challengeRepository.takeByTokenHash(tokenHash);
  },
};

const challenges = createEncryptedChallengeStore(persistedChallenges, {
  secret: env.AUTH_CHALLENGE_SECRET,
  previousSecrets: env.PREVIOUS_AUTH_CHALLENGE_SECRET
    ? [env.PREVIOUS_AUTH_CHALLENGE_SECRET]
    : [],
});

const identities: IdentityStore<AppUser> = {
  findUser: (provider, providerSubject) =>
    identityRepository.findUser(provider, providerSubject),
  resolve: (identity) =>
    database.transaction(async (transaction) => {
      const existing = await transaction.identities.findUser(
        identity.provider,
        identity.providerSubject,
      );
      if (existing) return existing;

      const user = await transaction.users.createFromIdentity(identity);
      await transaction.identities.insert({
        provider: identity.provider,
        providerSubject: identity.providerSubject,
        userId: user.id,
        email: identity.email,
        emailVerified: identity.emailVerified,
        claims: identity.claims,
      });
      return user;
    }),
};

const auth = createAuth({
  users,
  sessions,
  challenges,
  identities,
});

The repository names above are placeholders for your ORM or database layer. Preserve these storage rules:

  • Store AuthSessionRecord.tokenHash as the session lookup key. The raw token is returned only by createSession; send it in a secure cookie and never log or persist it.
  • Implement rotateByTokenHash as one atomic consume-and-replace operation. touchByTokenHash must never recreate a deleted session or shorten its expiry. These lifecycle capabilities fail closed when a store omits them.
  • Store AuthChallengeRecord.tokenHash as the continuation lookup key. consumeByTokenHash must atomically delete and return the record.
  • Wrap the persistence adapter with createEncryptedChallengeStore. Use a dedicated service-managed secret containing at least 32 bytes. Plaintext payload rows fail closed; keep old keys only for the lifetime of active challenges during rotation.
  • Index session and challenge hashes uniquely, index their expiry timestamps, and delete expired records periodically.
  • Make (provider, providerSubject) unique. Do not link accounts by an unverified email address in IdentityStore.resolve.

auth-core hashes raw session and continuation tokens with SHA-256 before it calls a store. Store adapters must not hash them again.

AuthUser.email is optional so guest, passkey-only, and provider-subject identities do not need fake email addresses. Email-based plugins require AuthUserWithEmail explicitly.