express-multitenant-kit
Version:
A lightweight helper module for building multi-tenant Express.js applications. Includes JWT-based route protection, dynamic route handling, and integration with express-tenant-router.
19 lines (15 loc) • 520 B
JavaScript
const jwt = require("jsonwebtoken");
function verifyTenantJWT(secret) {
return function (req, res, next) {
const token = req.cookies?.token || req.headers.authorization?.split(" ")[1];
if (!token) return res.status(401).json({ error: "Token missing" });
try {
const decoded = jwt.verify(token, secret);
req.tenantAuth = decoded;
next();
} catch (err) {
return res.status(401).json({ error: "Invalid token" });
}
};
}
module.exports = verifyTenantJWT;