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

@authu/node

v1.0.40

Published

Node.js SDK for AuthU - Centralized Multi-Tenant Authentication Service

Readme

@authu/node

Node.js SDK for AuthU - Centralized Multi-Tenant Authentication Service.

Installation

npm install @authu/node
# or
pnpm add @authu/node
# or
yarn add @authu/node

Usage

1. Verify JWT Tokens

Use verifyToken to validate and decode JWT tokens:

import {verifyToken} from '@authu/node';

const result = await verifyToken(token, {
  domain: 'auth.example.com',
  audience: 'https://api.example.com'
});

console.log(result.payload.sub); // User ID
console.log(result.payload.email); // User email

2. Fastify Middleware

Use createAuthUMiddleware to protect your Fastify routes:

import Fastify from 'fastify';
import {createAuthUMiddleware} from '@authu/node';

const fastify = Fastify();

// Register the middleware
fastify.register(
  createAuthUMiddleware({
    domain: 'auth.example.com',
    audience: 'https://api.example.com'
  })
);

// Protected route
fastify.get(
  '/api/profile',
  {preHandler: [fastify.verifyAuthU]},
  async request => {
    // Access the authenticated user
    return {user: request.authUUser};
  }
);

3. Optional Authentication

For routes where authentication is optional:

fastify.register(
  createAuthUMiddleware({
    domain: 'auth.example.com',
    optional: true
  })
);

fastify.get('/api/public', {preHandler: [fastify.verifyAuthU]}, async request => {
  if (request.authUUser) {
    return {message: `Hello ${request.authUUser.name}`};
  }
  return {message: 'Hello guest'};
});

4. Custom JWKS Client

For advanced use cases, you can provide your own JWKS client:

import {JwksClient, verifyToken} from '@authu/node';

const jwksClient = new JwksClient({
  jwksUri: 'https://auth.example.com/.well-known/jwks.json',
  cacheMaxAge: 300000 // 5 minutes cache
});

const result = await verifyToken(token, {
  domain: 'auth.example.com',
  jwksClient
});

API Reference

verifyToken(token, options)

Verifies and decodes a JWT token.

Options:

| Option | Type | Required | Description | |--------|------|----------|-------------| | domain | string | Yes | AuthU server domain (without https://) | | audience | string | No | Expected audience claim | | issuer | string | No | Expected issuer (default: https://{domain}) | | jwksClient | JwksClient | No | Custom JWKS client instance |

Returns: Promise<VerifiedToken>

createAuthUMiddleware(options)

Creates a Fastify plugin for JWT authentication.

Options:

| Option | Type | Required | Description | |--------|------|----------|-------------| | domain | string | Yes | AuthU server domain | | audience | string | No | Expected audience claim | | issuer | string | No | Expected issuer | | optional | boolean | No | If true, don't error on missing/invalid tokens |

Decorators added:

  • fastify.verifyAuthU - Prehandler function for route protection
  • request.authUUser - Authenticated user data (or null if optional)

JwksClient

JWKS client with automatic caching.

const client = new JwksClient({
  jwksUri: 'https://auth.example.com/.well-known/jwks.json',
  cacheMaxAge: 600000 // 10 minutes (default)
});

// Get a key by kid
const key = await client.getKey('key-id');

// Get all keys
const jwks = await client.getJwks();

// Clear cache
client.clearCache();

Types

interface AuthUUser {
  sub: string;
  email?: string;
  emailVerified?: boolean;
  name?: string;
  picture?: string;
  scope?: string;
  clientId?: string;
  tenantId?: string;
}

interface VerifiedToken {
  payload: AuthUUser;
  header: {
    alg: string;
    typ?: string;
    kid?: string;
  };
}

Development

Build

pnpm run build

Lint

pnpm run lint

Publishing

Prerequisites

  • Be logged in to npm: npm login
  • Have publish rights on @authu scope

Publish a New Version

  1. Update version in package.json
  2. Build and publish:
pnpm run build
pnpm publish --access public

The --access public flag is required for scoped packages.

License

MIT