This is my update request for updating a user, but the title is the output that am getting
router.put("/:id", verifyTokenAndAuthorization, async (req, res) => {
if (req.user.password) {
req.body.password = CryptoJS.AES.encrypt(
req.body.password,
process.env.PASS_SEC
).toString();
}
try {
const updatedUser = await User.findByIdAndUpdate(
req.user.id,
{
$set: req.body,
},
{ new: true }
);
res.status(200).json(updatedUser);
} catch (err) {
res.status(500).json(err);
}
});
But the request doesn't go past
const verifyTokenAndAuthorization = (req, res, next) => {
verifyToken(req, res, () => {
console.log("req recived for login");
if (req.user.id === req.params.id || req.user.isAdmin) {
console.log("req went past verification");
next();
} else {
res.status(403).json("You are not allowed to access!");
}
});
};
the problem is in before the output req went past verification
This is printed in my console
req recived for login Error = "Cannot read properties of undefined (reading 'id')" at E:\E-com Project\ver-one-zero-one-api\routes\verifyToken.js:20:18