@explita/cloud-auth-express
v0.1.1
Published
A simple authentication library for Node.js/Express.js
Maintainers
Readme
Part of the Explita Cloud Auth Platform
A lightweight authentication middleware for Node.js and Express.js — built as a core component of the Explita Cloud Auth platform. It simplifies authentication in your backend by providing easy-to-use utilities for managing tokens, sessions, cookies, and multi-factor auth with OTP support.
✨ Features
- 🔐 Seamless JWT session management
- 💼 Designed for Express.js APIs and server functions
- 📲 Supports both token-based and OTP-based authentication
- 🍪 Built-in cookie handling for secure session flow
🚀 Installation
npm install @explita/cloud-auth-expressor
yarn add @explita/cloud-auth-expressor
pnpm add @explita/cloud-auth-expressThis package only works with Express.js
Usage
import {
authenticateRequest,
requirePermission,
} from "@explita/cloud-auth-express";
const app = express();
//exclude paths that don't require authentication
const excludedPaths = ["/auth/register"];
app.use(authenticateRequest({ exclude: excludedPaths }));
//example of a protected route
app.get("/protected", (req, res) => {
res.send("This is a protected route, you are authenticated");
});
//require permission
app.get("/admin", requirePermission("admin"), (req, res) => {
res.send("This is an admin route");
});
//require role
app.get("/moderator", requirePermission("moderator"), (req, res) => {
res.send("This is a moderator route");
});
//available functions
verifyUser;
registerUser;
updateUser;
updateUserMetadata;
getUsers;
getUserById;
toggleUserStatus;
changePassword;
getRoles;
addRole;
updateRole;
assignPermission;Getting started
Sign up for an account at Explita Cloud, create a project, add auth service and get your API key from the dashboard and add it to your environment variables.
🔐 Authentication Methods
Use JWT tokens for stateless authentication. The library provides helpers to manage tokens and sessions using cookies.
📄 License
MIT — Made with ❤️ by Explita
