backend/middleware/authenticate.js

11 lines
276 B
JavaScript
Raw Permalink Normal View History

2023-07-28 03:36:07 +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();
});
2023-08-04 02:46:00 +00:00
}