auth-express

raw JSON →
0.0.62 verified Sat Apr 25 auth: no javascript abandoned

A middleware library for Express.js that provides a unified authentication box supporting multiple strategies (JWT, OAuth, session, etc.). Current stable version 0.0.62 (as of 2025) with minimal release cadence (no recent updates). Key differentiator: single-box configuration for auth, but lacks documentation and appears unmaintained. Alternatives like passport or express-jwt are more robust.

error Error: Cannot find module 'auth-express'
cause Package not installed or not in node_modules.
fix
Run npm install auth-express
error TypeError: Cannot read properties of undefined (reading 'secret')
cause Missing required options object when calling auth().
fix
Provide options: auth({ secret: 'mysecret' })
error SyntaxError: The requested module 'auth-express' does not provide an export named 'default'
cause Using CommonJS require() on an ESM-only module.
fix
Switch to import statement: import auth from 'auth-express'
deprecated auth-express is no longer maintained. Use passport or express-jwt instead.
fix Migrate to a maintained authentication library.
breaking Version 0.0.60 dropped support for CommonJS (require). Only ESM imports are allowed.
fix Use ES module syntax: import auth from 'auth-express'
gotcha The default export is a factory function, not middleware directly. Must call it with options first.
fix Use app.use(auth(options)) instead of app.use(auth)
npm install auth-express
yarn add auth-express
pnpm add auth-express

Initializes auth middleware with JWT secret and protects a route using auth.required guard.

import express from 'express';
import auth from 'auth-express';

const app = express();
app.use(auth({ secret: process.env.JWT_SECRET ?? 'default-secret' }));

app.get('/protected', auth.required, (req, res) => {
  res.json({ user: req.user });
});

app.listen(3000, () => console.log('Server running on port 3000'));