website/backend/middleware/authenticate.js

11 lines
276 B
JavaScript
Raw Permalink Normal View History

2024-02-08 14:07:13 +00:00
function authenticate(req, res, next) {
const token = req.header('Authorization');
if (!token) return res.sendStatus(401);
jwt.verify(token, 'SECRET_KEY', (err, decoded) => {
if (err) return res.sendStatus(401);
req.userId = decoded.userId;
next();
});
}