Chat report table working

This commit is contained in:
2021-03-28 07:57:56 +11:00
parent f83ef938ab
commit ab0bad4f73
6 changed files with 92 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
const jwt = require('jsonwebtoken');
//middleware to authenticate the JWT token
module.exports = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader?.split (' ')[1]; //'Bearer token'
if (!token) {
return res.status(401).send('No token found');
}
return jwt.verify(token, process.env.SECRET_ACCESS, (err, user) => {
if (err) {
return res.status(403).send(err);
}
req.user = user;
return next();
});
};