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

@zshn-dev/auth-server

v1.1.0

Published

Angular-first auth server SDK — Express router for GitHub OAuth

Readme

@zshn-dev/auth-server

GitHub OAuth + JWT authentication middleware for Express.


Installation

npm install @zshn-dev/auth-server

Quick Start

import express from 'express';
import { createAuthRouter, verifyJwt } from '@zshn-dev/auth-server';

const config = {
  clientId: process.env.GITHUB_CLIENT_ID!,
  clientSecret: process.env.GITHUB_CLIENT_SECRET!,
  jwtSecret: process.env.JWT_SECRET!,
  callbackUrl: 'http://localhost:3000/auth/github/callback',
  afterLoginUrl: 'http://localhost:4200/auth/callback',
};

const app = express();

// Mount the auth router at /auth
app.use('/auth', createAuthRouter(config));

// Protect routes with JWT middleware
app.get('/api/me', verifyJwt(config), (req, res) => {
  res.json({ user: req.user });
});

app.listen(3000, () => console.log('Server running on http://localhost:3000'));

After a successful login, GitHub redirects to callbackUrl, which exchanges the OAuth code for a JWT and then redirects the user to:

<afterLoginUrl>?token=<jwt>

API Reference

createAuthRouter(config: AuthServerConfig): Router

Returns an Express Router. Mount it at /auth:

app.use('/auth', createAuthRouter(config));

Routes:

| Method | Path | Description | | ------ | ----------------- | ------------------------------------------------------------------------ | | GET | /github | Redirects the user to the GitHub OAuth authorization page | | GET | /github/callback| Exchanges the OAuth code for a JWT; redirects to afterLoginUrl?token=… |


AuthServerConfig

| Property | Type | Required | Default | Description | | ----------------- | ----------------------------------------------- | -------- | -------------- | -------------------------------------------------------------- | | clientId | string | ✅ | — | GitHub OAuth App client ID | | clientSecret | string | ✅ | — | GitHub OAuth App client secret | | jwtSecret | string | ✅ | — | Secret used to sign/verify JWTs — must be 32+ characters | | callbackUrl | string | ✅ | — | Full URL GitHub redirects to after authorization | | afterLoginUrl | string | ✅ | — | URL of your frontend app; receives ?token=<jwt> on success | | transformUser | (profile: GitHubProfile) => Partial<User> | ❌ | — | Optional hook to customize the JWT payload from the GitHub profile | | stateCookieName | string | ❌ | oauth_state | Name of the cookie used to store the OAuth CSRF state value |


verifyJwt(config: AuthServerConfig): RequestHandler

Returns an Express middleware that validates a JWT on every request.

  • Reads the Authorization: Bearer <token> header
  • Verifies the token against config.jwtSecret
  • Sets req.user (typed as JwtPayload) on success
  • Returns 401 Unauthorized if the token is missing, invalid, or expired
app.get('/api/profile', verifyJwt(config), (req, res) => {
  res.json(req.user);
});

transformUser Hook

Use transformUser to control which fields from the GitHub profile are included in the JWT payload:

import { createAuthRouter, GitHubProfile } from '@zshn-dev/auth-server';

app.use('/auth', createAuthRouter({
  ...config,
  transformUser: (profile: GitHubProfile) => ({
    id: profile.id,
    login: profile.login,
    name: profile.name,
    avatarUrl: profile.avatar_url,
    email: profile.email,
  }),
}));

The returned object is merged into the JWT payload and later available on req.user.


Environment Variables

Never hardcode secrets. Use a .env file (via dotenv) or your deployment platform's secret management:

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
# Must be at least 32 characters
JWT_SECRET=a_very_long_random_secret_at_least_32_chars
import 'dotenv/config';

const config = {
  clientId: process.env.GITHUB_CLIENT_ID!,
  clientSecret: process.env.GITHUB_CLIENT_SECRET!,
  jwtSecret: process.env.JWT_SECRET!,
  callbackUrl: process.env.CALLBACK_URL ?? 'http://localhost:3000/auth/github/callback',
  afterLoginUrl: process.env.AFTER_LOGIN_URL ?? 'http://localhost:4200/auth/callback',
};

Add .env to your .gitignore to avoid committing secrets:

.env