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

flex-auth-core

v2.1.1

Published

Flexible Node.js authentication module supporting multiple credential strategies.

Readme

flex-auth-core

A flexible, plug-and-play authentication middleware for Node.js & Express. Supports multiple credential strategies like:

  • Email + Password
  • Email + Username + Password
  • Mobile + Username + Password
  • Google OAuth
  • GitHub OAuth

Designed for developers who want to drop in secure, customizable authentication logic into any Node.js backend.


📚 Table of Contents


📦 Installation

npm install flex-auth-core

Or from GitHub:

npm install git+https://github.com/AdarshYadav04/flex-auth.git

✨ Features

  • 🔐 Multiple auth strategies: email, username, mobile
  • 🌐 Built-in OAuth login via Google and GitHub
  • 🔧 Configurable with JWT and MongoDB
  • 🔄 Pluggable design for adding OTP in future versions
  • 📦 Easy Express integration
  • 🧰 Lightweight, fast, and dependency-friendly

📖 Docs & Community


⚡ Quick Start

const express = require('express');
const flexAuth = require('flex-auth-core');
require('dotenv').config();

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

const auth = flexAuth({
  jwtSecret: process.env.JWT_SECRET,
  mongoUri: process.env.MONGO_URI,
  enableOAuth: true
});

app.post('/register', (req, res) => auth.register({ ...req, method: req.body.method }, res));
app.post('/login', (req, res) => auth.login({ ...req, method: req.body.method }, res));

// Enable OAuth routes
auth.useOAuth(app);

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

🔐 Authentication Methods

📌 Credential-Based

  • email-password
  • email-username-password
  • mobile-username-password

Each request to /register or /login must include a method field and the relevant credentials in the request body.

🌐 OAuth-Based

✅ Google Login

  • Visit: GET /auth/google
  • Callback: GET /auth/callback/google

✅ GitHub Login

  • Visit: GET /auth/github
  • Callback: GET /auth/callback/github

📦 On success, you’ll receive a JWT token:

{
  "message": "OAuth login success",
  "token": "your.jwt.token"
}

Add the following to your .env:

//Required
JWT_SECRET=your_jwt_secret_here  
MONGO_URI=mongodb+srv://your_user:[email protected]/your_db 

// Only if using OAuth
GOOGLE_CLIENT_ID=your_google_client_id  
GOOGLE_CLIENT_SECRET=your_google_client_secret
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
OAUTH_CALLBACK=http://localhost:3000/auth/callback
CLIENT_BASE_URL=http://localhost:5173

Ensure the callback URLs are registered in Google/GitHub developer settings:

  • Google: http://localhost:3000/auth/callback/google
  • GitHub: http://localhost:3000/auth/callback/github

🧪 Running Tests

npm test

Tests are currently basic and will be extended in future versions with Jest/Mocha.


💡 Philosophy

  • Minimal configuration, maximum flexibility
  • Secure by design using bcrypt and JWT
  • Easy to extend with additional auth methods (e.g. Google, GitHub, OTP)
  • Zero vendor lock-in

🧩 Examples

Example usage in a standalone Express app:

  • See example-app.js in the repo

🙌 Contributing to flex-auth-core

We welcome contributions! To get started:

  1. Fork the repo
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make changes and commit: git commit -m 'Add XYZ feature'
  4. Push to your fork: git push origin feature/your-feature-name
  5. Create a Pull Request

👨‍🔬 TC (Technical Committee)

The initial maintainer and current decision-maker:

Future contributors and collaborators welcome.


📄 License

MIT © Adarsh Yadav