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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vedaxon-auth-framework

v1.0.2

Published

A reusable authentication framework for Node.js apps

Downloads

120

Readme

Vedaxon Auth Framework

A lightweight, reusable authentication framework for Node.js applications.
Designed for developers who want clean JWT authentication, password hashing, and plug-and-play Express.js middleware without the overhead of large auth libraries.


🚀 Features

  • 🔐 Generate & verify JWT tokens
  • 🔑 Password hashing & comparison using bcrypt
  • 🧩 Express middleware for protected routes
  • 🧱 Session object creator
  • ⚠️ Custom AuthError class for consistent API responses
  • ⚙️ Configurable via environment variables or programmatically
  • 🪶 Small, minimal, dependency-lean library

📦 Installation

npm install vedaxon-auth-framework

🧠 Quick Usage Example

const express = require("express");
const {
  generateToken,
  verifyToken,
  hashPassword,
  comparePassword,
  createSession,
  authMiddleware,
  AuthError
} = require("vedaxon-auth-framework");

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

// Example protected route
app.get("/profile", authMiddleware, (req, res) => {
  res.json({ message: "Access granted", user: req.user });
});

// Example signup flow
app.post("/signup", async (req, res) => {
  const { email, password } = req.body;
  const hashed = await hashPassword(password);

  // Save user to DB and respond
  res.json({ email, password: hashed });
});

// Example login flow
app.post("/login", async (req, res) => {
  const { user, password } = req.body;

  const match = await comparePassword(password, user.password);
  if (!match) throw new AuthError("Invalid credentials", 401);

  const token = generateToken({ id: user.id, email: user.email });

  res.json(createSession(user, token));
});

app.listen(5000, () => console.log("Auth server running"));

🔧 API Reference

1. generateToken(payload, expiresIn = "1h")

Create a JWT token from a payload.

2. verifyToken(token)

Verify and decode a JWT token.

3. hashPassword(password)

Securely hash a password using bcrypt.

4. comparePassword(password, hash)

Compare raw password with hashed password.

5. createSession(user, token)

Generate a standardized response session object.

6. authMiddleware(req, res, next)

Protect routes by validating the Authorization header.

7. AuthError(message, statusCode)

Custom error class for unified error handling.


🛠️ Environment Variables (Optional)

| Variable | Description | |------------------|------------------------------------| | JWT_SECRET | Secret key for signing tokens | | JWT_EXPIRES_IN | Token expiry (default: 1h) |


📘 Example Database Schema (Optional)

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT UNIQUE NOT NULL,
  password TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

💡 Ideal For

  • REST APIs
  • SaaS apps
  • CRM/ERP dashboards
  • Multi-tenant platforms
  • Microservices needing lightweight auth

📄 License

MIT