1.0.1 ⢠Published 4 months ago
express-authentication-validator v1.0.1
Express Authentication Validator š
A lightweight, customizable middleware for validating authentication inputs in Express.js applications.
It helps developers secure login, registration, and password reset forms with minimal effort.
š Features
ā
Easy to Use ā Plug and play middleware integration
ā
Customizable ā Define your own validation rules
ā
Security-Enhanced ā Prevents common input vulnerabilities
ā
Minimal Setup ā Works with Express Validator
š¦ Installation
npm install express-authentication-validator
š§ Usage
Basic Setup
Import and use the middleware in your Express routes:
const express = require("express");
const {
registerValidator,
errorHandler,
} = require("express-authentication-validator");
const app = express();
app.use(express.json());
app.post("/register", registerValidator, errorHandler, (req, res) => {
const { username, email, password, confirmPassword } = req.body;
res.send({ username, email });
});
app.listen(3000, () => console.log("Server running on port 3000"));
āļø Customization
Want to override validation rules? Use custom rules like this:
const express = require("express");
const customValidator = require("express-auth-validator");
const registerValidation = customValidator({
name: { method: "notEmpty", args: [], message: "Name field is required" },
email: { method: "isEmail", args: [], message: "Invalid email format" },
password: { method: "isLength", args: [{ min: 8 }], message: "Password must be at least 8 characters" },
});
šÆ Why Use Express Auth Validator?
š Saves time by reducing repetitive validation code
š Adds security by enforcing strong input rules
š Provides ready-to-use authentication validation