In my controller, I currently have the following code:
module.exports.validateToken = (req, res, next) => {
const token = req.cookies.jwt;
//console.log(token);
if (!token) {
return res.sendStatus(403);
}
try {
const data = jwt.verify(token, "secret token");
console.log(data);
req.userId = data.id;
return next();
} catch {
return res.sendStatus(403);
}
};
This code is then used by a route like this:
router.get("/secure-route", authController.validateToken, (req, res) => {
return res.json({ user: { id: req.userId, role: req.userRole } });
});
I am now trying to retrieve the JSON response from that route in a different controller but haven't been successful so far. Any suggestions?