Code
this is my code in VS code to check if the user is an admin or a user
exports.authorizeRoles = (...roles) => {
return (req, res, next) => {
if (!roles.includes(req.user.role)) {
return next(
new ErrorHandler(
`Role: ${req.user.role} is not allowed to access this resource`,
403
)
);
}
next();
};
};
Error in postman API
the used declaration should be fine i don't know what's this problem
"success": false,
"message": "Cannot read properties of null (reading 'role')"