Spaces:
Sleeping
Sleeping
; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
exports.authenticateToken = void 0; | |
var jsonwebtoken_1 = require("jsonwebtoken"); | |
var authenticateToken = function (req, res, next) { | |
var authHeader = req.headers['authorization']; | |
var token = authHeader && authHeader.split(' ')[1]; // Bearer TOKEN | |
if (!token) { | |
return res.status(401).json({ error: 'Access token required' }); | |
} | |
try { | |
var decoded = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET); | |
req.user = { | |
userId: decoded.userId, | |
tenantId: decoded.tenantId | |
}; | |
next(); | |
} | |
catch (error) { | |
return res.status(403).json({ error: 'Invalid or expired token' }); | |
} | |
}; | |
exports.authenticateToken = authenticateToken; | |