My question:
I have been creating a node backend webtoken. When I tested it through POSTMAN API. It’s showing “Sending Request” and no result are returning. The code is given below.
Details (like screenshots):
const jwt = require("jsonwebtoken");
const verifyToken = (req, res, next) => {
const authHeader = req.headers.token;
if (authHeader) {
const token = authHeader.split(" ")[1];
jwt.verify(token, process.env.JWT_SEC, (err, user) => {
if (err){
res.status(403).json("Token is not valid!");
req.user = user;
next();
}
});
} else {
return res.status(401).json("YOu are not authenticated!");
}
};
const verifyTokenAndAuthorization = (req, res, next) => {
verifyToken(req, res, () => {
if (req.user.id === req.params.id || req.user.isAdmin) {
next();
} else {
res.status(403).json("You are not allowed to do that!");
}
});
};
module.exports = { verifyToken,verifyTokenAndAuthorization };