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

@workkit/auth

v0.1.1

Published

Auth handler patterns for Cloudflare Workers — JWT validation, session management, typed auth context

Downloads

267

Readme

@workkit/auth

JWT, session management, and auth middleware for Cloudflare Workers

npm bundle size

Install

bun add @workkit/auth

Usage

Before (manual JWT and auth)

// 50+ lines of WebCrypto boilerplate for JWT
const encoder = new TextEncoder()
const keyData = encoder.encode(secret)
const key = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: "SHA-256" }, false, ["sign"])
// ... base64url encode header, payload, sign, concatenate ...

// Manual bearer extraction
const auth = request.headers.get("Authorization")
if (!auth?.startsWith("Bearer ")) return new Response("Unauthorized", { status: 401 })
const token = auth.slice(7)
// ... verify, check expiry, parse claims ...

After (workkit auth)

import {
  signJWT,
  verifyJWT,
  createAuthHandler,
  createSessionManager,
  extractBearerToken,
  hashPassword,
  verifyPassword,
} from "@workkit/auth"

// Sign and verify JWTs
const token = await signJWT({ sub: userId, role: "admin" }, env.JWT_SECRET, {
  expiresIn: "7d",
  algorithm: "HS256",
})
const claims = await verifyJWT(token, env.JWT_SECRET) // typed claims

// Auth middleware — wrap any handler
const auth = createAuthHandler({
  verify: async (request, env) => {
    const token = extractBearerToken(request)
    if (!token) return null
    return await verifyJWT(token, env.JWT_SECRET)
  },
})

// Protected route — returns 401 if not authenticated
const handler = auth.required(async (request, env, ctx, claims) => {
  return new Response(`Hello ${claims.sub}`)
})

// Role-based — returns 403 if wrong role
const adminHandler = auth.requireRole("admin", async (request, env, ctx, claims) => {
  return new Response("Admin panel")
})

// Session management with KV
const sessions = createSessionManager({
  kv: env.SESSIONS_KV,
  ttl: 86400,
  cookie: { name: "sid", secure: true, sameSite: "Lax" },
})
const { sessionId, headers } = await sessions.create({ userId: "123" })
const session = await sessions.get(request) // reads from cookie

// Password hashing (PBKDF2)
const hashed = await hashPassword("my-password")
const valid = await verifyPassword("my-password", hashed)

API

JWT

  • signJWT(claims, secret, options?) — Sign a JWT. Options: expiresIn, algorithm (HS256/HS384/HS512)
  • verifyJWT(token, secret, options?) — Verify and decode a JWT
  • decodeJWT(token) — Decode without verification (for inspection)

Auth Handler

  • createAuthHandler(config) — Framework-agnostic auth middleware
    • .required(handler) — 401 if not authenticated
    • .optional(handler) — Auth context may be null
    • .requireRole(role, handler) — 403 if wrong role

Sessions

  • createSessionManager(config) — KV-backed session management
    • .create(data) — Create session, returns { sessionId, headers }
    • .get(request) — Get session from cookie
    • .destroy(request) — Delete session

Utilities

  • extractBearerToken(request) — Extract token from Authorization: Bearer ...
  • extractBasicAuth(request) — Extract { username, password } from Basic auth
  • hashPassword(password) — PBKDF2 password hash
  • verifyPassword(password, hash) — Verify password against hash

License

MIT