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

@fabrk/auth

v0.3.1

Published

Authentication adapters for FABRK framework (NextAuth, API keys, MFA)

Downloads

328

Readme

@fabrk/auth

Authentication adapters for the FABRK framework. Supports NextAuth, API keys, and MFA (TOTP + backup codes).

Installation

npm install @fabrk/auth

Usage

import { createNextAuthAdapter } from '@fabrk/auth'
import { auth } from './lib/auth' // your NextAuth v5 auth()

const authAdapter = createNextAuthAdapter({
  authInstance: auth,
  providers: ['google', 'credentials'],
  sessionStrategy: 'jwt',
})

// Get session
const session = await authAdapter.getSession(request)

API Keys

import { generateApiKey, hashApiKey, createApiKeyValidator } from '@fabrk/auth'

// Generate a key (format: fabrk_live_xxxxx)
const { key, prefix, hash } = await generateApiKey({
  prefix: 'fabrk',
  environment: 'live',
})

// Validate a key
const validator = createApiKeyValidator(apiKeyStore)
const keyInfo = await validator.validate(key)

if (keyInfo && validator.hasScope(keyInfo, 'write')) {
  // Authorized
}

MFA (TOTP + Backup Codes)

import {
  generateTotpSecret,
  generateTotpUri,
  verifyTotp,
  generateBackupCodes,
  hashBackupCodes,
  verifyBackupCode,
} from '@fabrk/auth'

// Setup TOTP
const secret = generateTotpSecret()
const uri = generateTotpUri(secret, '[email protected]', 'MyApp')
// Display URI as QR code in authenticator app

// Verify a 6-digit code
const valid = await verifyTotp(secret, '123456')

// Generate backup codes (format: XXXX-XXXX)
const codes = generateBackupCodes(10)
const hashed = await hashBackupCodes(codes)

// Verify a backup code
const { valid: isValid, matchedIndex } = await verifyBackupCode('A1B2-C3D4', hashed)

Middleware

import { withAuth, withApiKey, withAuthOrApiKey } from '@fabrk/auth'

// Require session auth
export const POST = withAuth(authAdapter, async (req, session) => {
  return Response.json({ user: session.userId })
})

// Require API key with scopes
export const GET = withApiKey(authAdapter, async (req, keyInfo) => {
  return Response.json({ key: keyInfo.name })
}, { requiredScopes: ['read'] })

// Accept either session or API key
export const PUT = withAuthOrApiKey(authAdapter, async (req, { session, apiKey }) => {
  return Response.json({ authenticated: true })
})

Features

  • NextAuth Adapter - Wraps Auth.js v5 with a unified AuthAdapter interface; accepts your auth() function for real session retrieval
  • API Key Generation - Cryptographically secure keys in prefix_env_random format with SHA-256 hashing for storage
  • API Key Validation - Hash-based lookup with scope/permission checking and wildcard support
  • TOTP (RFC 6238) - Time-based one-time passwords with configurable time window for clock skew tolerance
  • Backup Codes - One-time-use recovery codes formatted as XXXX-XXXX with ambiguous characters removed
  • Auth Middleware - withAuth, withApiKey, and withAuthOrApiKey route wrappers for session and API key protection
  • In-Memory Stores - InMemoryAuthStore and InMemoryApiKeyStore for development and testing
  • Web Crypto API - All cryptographic operations use the Web Crypto API with no Node.js-specific dependencies

Documentation

View full documentation

License

MIT