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

@iron-stack/auth

v1.0.1

Published

Full-stack authentication framework with JWT access tokens, rotating refresh tokens, and role-based access control -- built for tRPC + Fastify + Drizzle.

Readme

@iron-stack/auth

Full-stack authentication framework with JWT access tokens, rotating refresh tokens, and role-based access control -- built for tRPC + Fastify + Drizzle.

Installation

npm install @iron-stack/auth

Quick Start

Server

import { createAuthRouter, extractAuthContext, authRequired, requireRole, createSocketAuthMiddleware } from '@iron-stack/auth/server';

// 1. Create the auth tRPC router (register, login, refresh, logout)
const authRouter = createAuthRouter({
  router: t.router,
  publicProcedure,
  db,
  tables: { users, refreshTokens },
  jwtSign: (payload, opts) => fastify.jwt.sign(payload, opts),
});

// 2. Extract auth context from requests
function createContext({ req }: CreateFastifyContextOptions) {
  return { db, ...extractAuthContext(fastify, req) };
}

// 3. Protect routes
const protectedProcedure = t.procedure.use(authRequired);
const adminProcedure = t.procedure.use(requireRole(['admin']));

// 4. Authenticate Socket.IO connections
io.use(createSocketAuthMiddleware(fastify));

Client

import { create } from 'zustand';
import { createAuthStore } from '@iron-stack/auth/client';
import type { AuthState } from '@iron-stack/auth/client';

export const useAuthStore = create<AuthState>((set, get) =>
  createAuthStore({
    apiUrl: 'http://localhost:3000',
    storage: {
      get: async () => { /* read refresh token from secure storage */ },
      set: async (token) => { /* persist refresh token */ },
      remove: async () => { /* delete refresh token */ },
    },
  })(set, get)
);

API Reference

@iron-stack/auth (shared)

| Export | Description | |---|---| | RegisterSchema | Zod schema for registration input (phone, displayName, password) | | LoginSchema | Zod schema for login input (phone, password) | | RefreshSchema | Zod schema for token refresh input (refreshToken) | | AuthResponseSchema | Zod schema for auth response (tokens + user) | | RoleSchema | Zod enum schema for roles (user, admin, moderator) | | DEFAULT_ROLE | Default role assigned to new users ("user") | | RegisterInput | Type inferred from RegisterSchema | | LoginInput | Type inferred from LoginSchema | | RefreshInput | Type inferred from RefreshSchema | | AuthResponse | Type inferred from AuthResponseSchema | | Role | Type union: "user" \| "admin" \| "moderator" | | RolePermissions | Interface for defining resource/action role mappings |

@iron-stack/auth/server

| Export | Description | |---|---| | createAuthRouter(config) | Creates a tRPC router with register, login, refresh, and logout mutations | | authRequired | tRPC middleware that enforces authentication | | requireRole(roles) | Factory that returns a tRPC middleware enforcing role-based access | | extractAuthContext(fastify, req) | Extracts userId and userRole from a Fastify request's JWT | | createSocketAuthMiddleware(fastify) | Socket.IO middleware that verifies JWT from handshake auth | | generateRefreshToken() | Generates a cryptographically random refresh token | | hashToken(token) | SHA-256 hashes a token for safe storage | | AuthRouterConfig | Configuration interface for createAuthRouter | | AuthContext | Interface: { userId: string \| null, userRole: Role \| null } | | JwtPayload | Interface: { sub: string, role?: Role } | | SocketAuthPayload | Interface for socket JWT payload |

@iron-stack/auth/client

| Export | Description | |---|---| | createAuthStore(config) | Creates platform-agnostic auth state logic for Zustand | | AuthUser | Interface for the authenticated user object | | AuthState | Interface for the full auth store state and actions | | AuthStoreConfig | Configuration interface for the auth store |

Configuration

AuthRouterConfig

| Option | Type | Default | Description | |---|---|---|---| | router | function | required | tRPC t.router function | | publicProcedure | object | required | tRPC public procedure builder | | db | DrizzleDb | required | Drizzle database instance | | tables | { users, refreshTokens } | required | Drizzle table references | | jwtSign | function | required | JWT signing function | | bcryptRounds | number | 12 | Bcrypt hashing rounds | | accessTokenExpiry | string | "15m" | Access token expiration | | refreshTokenDays | number | 30 | Refresh token validity in days | | defaultRole | Role | "user" | Default role for new registrations |

AuthStoreConfig

| Option | Type | Default | Description | |---|---|---|---| | apiUrl | string | required | API base URL | | refreshPath | string | "auth.refresh" | tRPC refresh procedure path | | storage | { get, set, remove } | required | Secure storage adapter for refresh tokens |

License

MIT