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

kit-de-aut

v1.1.5

Published

A **flexible, database-agnostic authentication library for Express** that removes repetitive auth logic while letting developers fully control their **User model** and database.

Readme

🔐 Auth Engine

A flexible, database-agnostic authentication library for Express that removes repetitive auth logic while letting developers fully control their User model and database.

No mongoose ownership. No schema lock-in. Plug in your own User model and go.


✨ Features

  • ✅ Signup, Login, Logout
  • ✅ Get current user (/me)
  • ✅ Update user (fully configurable)
  • ✅ Delete user
  • ✅ JWT-based authentication
  • ✅ HTTP-only cookies
  • ✅ Zero database coupling
  • ✅ Highly configurable & secure defaults

📦 Installation

npm install auth-engine

🧠 Core Philosophy

This library does not own your database or schema.

You provide:

  • Your own User model
  • Your own DB connection (MongoDB, Prisma, TypeORM, etc.)

The library provides:

  • Authentication logic
  • Token & cookie handling
  • Secure, reusable controllers

📋 UserModel Contract (IMPORTANT)

Your UserModel must support the following methods:

UserModel.create(data)
UserModel.findOne(query)
UserModel.findById(id)
UserModel.findByIdAndUpdate(id, data, options)
UserModel.findByIdAndDelete(id)

Password Requirement

  • User model must contain a password field
  • Password should be selectable during login

Example (Mongoose):

password: { type: String, select: false }

⚙️ Initialization

You must initialize the library once before using any controller.

import { authConfig } from "auth-engine";
import User from "./models/User.js";

authConfig({
  UserModel: User,
  jwtSecret: process.env.JWT_SECRET,
  jwtExpiry: "7d",            // optional
  cookieName: "token",        // optional
  cookieOptions: {             // optional
    sameSite: "strict",
  },
});

🧩 Controllers & Middleware

Import

import {
  signup,
  login,
  logout,
  getMe,
  updateUser,
  deleteUser,
  protect,
} from "auth-engine";

🛣️ Example Routes Setup

import express from "express";
import cookieParser from "cookie-parser";

const app = express();
app.use(express.json());
app.use(cookieParser());

const router = express.Router();

router.post(
  "/signup",
  signup({
    required: ["email", "password"],
    unique: ["email"],
    allowed: ["name"],
  })
);

router.post("/login", login());
router.post("/logout", logout());

router.get("/me", protect(), getMe());

router.put(
  "/update",
  protect(),
  updateUser({
    allowed: ["name", "avatar"],
  })
);

router.delete("/delete", protect(), deleteUser());

app.use("/auth", router);

📝 Controller Options

🔹 signup(options)

signup({
  required: string[], // required fields
  unique: string[],   // must be unique
  allowed: string[],  // optional fields
});

🔹 login(options)

login({
  loginWith: "email",       // field used for login
  passwordField: "password" // password field name
});

🔹 getMe(options)

getMe({
  fields: ["name", "email"] // fields to return
});

If omitted, defaults to:

-password -__v

🔹 updateUser(options)

updateUser({
  allowed: ["name", "email"],
  allowPasswordUpdate: false,
  reIssueToken: false,
});

| Option | Description | | --------------------- | ------------------------ | | allowed | Fields user can update | | allowPasswordUpdate | Allow password changes | | reIssueToken | Refresh JWT after update |


🔹 deleteUser()

Deletes the currently authenticated user only.


🔹 protect()

Authentication middleware.

  • Reads token from:

    • HTTP-only cookie
    • Authorization: Bearer <token> header

Adds:

req.userId

🔐 Security Defaults

  • HTTP-only cookies
  • Secure cookies in production
  • SameSite protection
  • Password hashing using bcrypt
  • JWT expiration enforced

❌ What This Library Does NOT Do

  • ❌ Create database connections
  • ❌ Define schemas
  • ❌ Handle roles/permissions
  • ❌ Send emails

(You stay in control.)


🧪 Supported Databases

Works with any database layer that satisfies the UserModel contract:

  • MongoDB (Mongoose)
  • Prisma
  • TypeORM
  • Sequelize
  • Custom adapters

🚀 Why Use Auth Engine?

  • Stop rewriting auth logic
  • Full schema freedom
  • Production-safe defaults
  • Hackathon & startup friendly
  • Clean, documented API

📄 License

MIT


❤️ Final Note

This library is designed to be invisible — it should feel like part of your app, not a limitation.

If you need refresh tokens, OAuth, roles, or adapters — build on top of this foundation.

Happy shipping 🚀