danielfsousa / express-rest-boilerplate

⌛️ Express starter for building RESTful APIs
MIT License
2.36k stars 623 forks source link

Auth middleware wrong check ? #574

Open matamune94 opened 2 years ago

matamune94 commented 2 years ago

I found a piece of code that is difficult to understand

  if (roles === LOGGED_USER) {
    if (user.role !== 'admin' && req.params.userId !== user._id.toString()) {
      apiError.status = httpStatus.FORBIDDEN
      apiError.message = 'Forbidden'
      return next(apiError)
    }
  }

This roles === LOGGED_USER how can equal ? roles is Array type and LOGGED_USER is String type.