0

This function is always returning true when trying to authenticate the user:

exports.IsUser = function(req, res, next) {
    if (req.user.role === "user") {
        next();
    } else {
       return res.status(401).json({ message: 'Unauthorized user!' });
    }
};

The json req.user:

{
    "email": "test@gmail.com",
    "fullName": "testname",
    "role": "user",
    "iat": 1502495033
}

the routing function:

app.route('/')
    .get(function(req, res, next) {
    res.json(req.user);})
    .post(control.IsUser);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Omar Salem
  • 25
  • 6

0 Answers0