New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

simple-auth-express

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-auth-express

Simple username/password authentication for Express apps using JWT

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

simple-auth-express

🔐 Simple plug-and-play authentication for Express apps using JWT and bcrypt.

simple-auth-express provides ready-to-use login, registration, and JWT-based authentication middleware to get you up and running with username/password auth in minutes.

✨ Features

  • 🔑 Register and login endpoints (/auth/register, /auth/login)
  • 🔐 JWT-based token authentication with requireAuth middleware
  • 🔒 Passwords hashed securely using bcrypt
  • ⚙️ Lightweight and easy to integrate into any Express.js app
  • 🛡 In-memory user store (for demo purposes) — pluggable with your DB

📦 Installation

npm install simple-auth-express

🛠 Usage

1. Setup .env file

JWT_SECRET=your_secret_key_here

2. Integrate into Express App

require('dotenv').config();
const express = require('express');
const { authRoutes, requireAuth } = require('simple-auth-express');

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

// Public Auth Routes
app.use('/auth', authRoutes);

// Protected Route Example
app.get('/protected', requireAuth, (req, res) => {
  res.json({ message: `Hello ${req.user.username}` });
});

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

🔄 API Endpoints

POST /auth/register

Registers a new user.

Body:

{
  "username": "john",
  "password": "secure123"
}

Responses:

  • 201 Created: { "success": true }
  • 400 Bad Request: { "error": "User exists" }

POST /auth/login

Logs in a user and returns a JWT.

Body:

{
  "username": "john",
  "password": "secure123"
}

Response:

{
  "token": "<JWT Token>"
}

GET /protected

A sample protected route. Requires a valid JWT.

Header:

Authorization: Bearer <your_token>

Response:

{
  "message": "Hello john"
}

🧪 Development Mode (Optional)

To test the module locally:

  • Clone the repo
  • Add a file called example.js with the following:
require('dotenv').config();
const express = require('express');
const { authRoutes, requireAuth } = require('./src');

const app = express();
app.use(express.json());
app.use('/auth', authRoutes);

app.get('/protected', requireAuth, (req, res) => {
  res.json({ message: `Hello ${req.user.username}` });
});

app.listen(3000, () => console.log('Listening on port 3000'));
  • Run:
node example.js

🚧 Notes

  • 🔒 This version uses an in-memory user store for simplicity. Replace it with a proper DB in production.
  • 🧪 This package is intended for quick prototyping, learning, and extension.

📄 License

MIT

🙋‍♂️ Author

Made with ❤️ by Suren Dias

Keywords

express

FAQs

Package last updated on 17 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts