33 lines
732 B
JavaScript
33 lines
732 B
JavaScript
const { verify } = require('jsonwebtoken');
|
|
|
|
module.exports = {
|
|
authVerify: (req, res, next) => {
|
|
let token = req.get('authorization');
|
|
|
|
if (token) {
|
|
|
|
token = token.slice(7);
|
|
verify(token, process.env.JWT_KEY, (err, decoded) => {
|
|
|
|
if (err) {
|
|
|
|
res.json({
|
|
"Code": "2",
|
|
"Message": "Unauthorized Credentials"
|
|
})
|
|
}
|
|
else {
|
|
|
|
next();
|
|
}
|
|
|
|
});
|
|
}
|
|
else {
|
|
res.json({
|
|
"success": "0",
|
|
"message": "Unauthorized user Credentials"
|
|
})
|
|
}
|
|
}
|
|
} |