I have an server and i use jws to generate a token and the store it in a cookie, but when i try to authenticate the router cant find the cookie it just returns undefined
Express router
const { adminAuth } = require("../middleware/auth");
router.route("/deleteUser").delete(adminAuth, deleteUser);
middleware/auth
exports.adminAuth = (req, res, next) => {
console.log(req.cookies);
const token = req.cookies.jwt;
if (token) {
jwToken.verify(token, jwtSecret, (err, decodedToken) => {
if (err) {
return res.status(401).json({ message: "Not authorized" });
} else {
if (decodedToken.role !== "admin") {
return res.status(401).json({ message: "Not authorized" });
} else {
next();
}
}
});
} else {
return res
.status(401)
.json({ message: "Not authorized, token not available" });
}
};
I have checked that the adminAuth works it just dont work when i access it through the router. i where expecting that it would just pass through the router but aprently the cookies does not