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

jwt-baba

v1.1.1

Published

JWT authentication system made easy, secure, and fun — just say 'jai baba ki'.

Readme

🔐 JWT BABA

Secure authentication in seconds — just chant jai baba ki 🧙‍♂️
🔥 Plug & Play JWT Auth for Express + MongoDB


Story ...

To ye baat hai aaj se 4000 saal purani, jb m authentication m problem face krta tha ,, m bahut pareshaan tha ,,,

🧠 What is JWT BABA?

A zero-config authentication package for Node.js developers using Express and MongoDB.
Easily add registration, login, JWT tokens, and protected routes — in less than 1 minute.


📦 Installation

npm install jwt-baba

⚙️ Environment Setup

.env file in root:

PORT=5000
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/myDB
JWT_SECRET=shreyankislegend

🚀 Quick Start

📝 server.js

const express = require('express');
const cors = require('cors');
const app = express();
require('dotenv').config();

// ✅ Add Middleware
app.use(cors({ origin: 'http://localhost:5173', credentials: true }));
app.use(express.json());

// ✅ Initialize JWT-BABA
const initAuthSystem = require('jwt-baba');
initAuthSystem(app); // 🪄 Baba is activated!

🔐 Auth Routes Provided

| Method | Route | Description | |--------|-----------------------|-------------------------------| | POST | /api/auth/register | Register user | | POST | /api/auth/login | Login & get JWT token | | GET | /protected | Test-protected route |

🧾 Token Format (Frontend)

Authorization: Bearer <your_token>

✨ Add Custom Fields to User

Want to save image, bio, phoneNumber, etc? Easy!

✅ Step 1: Create Custom User Model

// models/User.js

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  name: String,
  email: { type: String, unique: true },
  password: String,
  image: String,
  bio: String,
  dob: Date,
  phoneNumber: String,
});

module.exports = mongoose.models.User || mongoose.model('User', userSchema);

✅ Step 2: Inject Custom User

const initAuthSystem = require('jwt-baba');
const customUserModel = require('./models/User');

initAuthSystem(app, { customUserModel });

🧙‍♂️ Using authMiddleware

JWT-BABA provides ready-made middleware to protect any route.

✅ Import & Apply

const { authMiddleware, User } = require('jwt-baba');

app.get('/me', authMiddleware, async (req, res) => {
  try {
    const user = await User.findById(req.user.id).select('-password');
    res.json(user);
  } catch (err) {
    res.status(500).json({ message: 'Something went wrong' });
  }
});

🔥 req.user already contains decoded ID & email


📂 Project Structure (Recommended)

your-app/
├── models/
│   └── User.js          # ← custom user schema
├── routes/
│   └── other-routes.js
├── server.js
└── .env

💻 React Integration Guide

✅ Step 1: Registration + Auto Login

const handleRegister = async () => {
  const res = await axios.post('http://localhost:5000/api/auth/register', {
    name, email, password
  });

  // 🧙 Auto-login after register
  const loginRes = await axios.post('http://localhost:5000/api/auth/login', {
    email, password
  });

  localStorage.setItem('authToken', loginRes.data.token);
  alert("User logged in!");
};

✅ Step 2: Protecting React Routes

useEffect(() => {
  const fetchUser = async () => {
    const token = localStorage.getItem('authToken');
    if (!token) return;

    const res = await axios.get('http://localhost:5000/me', {
      headers: {
        Authorization: `Bearer ${token}`
      }
    });
    console.log(res.data); // ← Logged-in user info
  };

  fetchUser();
}, []);

🧾 Axios with Token (Frontend)

axios.get('http://localhost:5000/me', {
  headers: {
    Authorization: `Bearer ${localStorage.getItem('authToken')}`
  }
});

📸 Screenshots


🧪 Future Roadmap

  • [ ] npx create-baba-app CLI
  • [ ] OAuth login (Google, GitHub)
  • [ ] Admin/Role middleware
  • [ ] Built-in UI components for login/register
  • [ ] TypeScript Support

⚠️ Name Protection Notice

jwt-baba is a creative identity built with love and purpose.

Please don’t publish similarly named packages on NPM.
If inspired, feel free to fork — just credit the baba 🙏

"Saaf shabdo m ye naam use mt krna ghode "

👨‍💻 Author

Made with ❤️ by Shreyank Agrawal

“Phool hai gulaab ka, sugandh lijiye,
Unemployed hai guys , support kijiye.” 😄


🧙‍♂️ Final Blessing

# In your terminal after setup:
jai baba ki 🔥

Thanks for using JWT BABA — may your APIs stay protected and bugs stay away!

🧙‍♂️ Contributions

Pull requests are welcome. For major changes, open an issue first. Respect Baba. Respect Auth.

📜 License

MIT

See You Soon Vatsh