Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Cannot read property 'includes' of undefined when a certain role is used

This error message displays while signing up when I write a certain role such as admin

This is the function and I don't think that there's a problem in it.

checkRolesExisted = (req, res, next) => {
if (req.body.roles) {
    for (let i = 0; i < req.body.roles.length; i++) {
    if (!ROLES.includes(req.body.roles[i])) {
        res.status(400).send({
        message: "Failed! Role does not exist = " + req.body.roles[i]
        });
        return;
    }
    }
}

next();
};

I add some code that I suspect has a problem:

exports.signup_post = (req,res) => {
  User.create({
    username: req.body.username,
    email: req.body.email,
    password: bcrypt.hashSync(req.body.password , 8)
  }).then(user => {
    if (req.body.roles){
        Role.findAll({ 
            where: {name:{
                [op.or]:req.body.roles
            }}
        }).then(roles => {
            user.setRoles(roles).then(() => {res.send({message:"user was registered succefully!"})})
        })
    }else{user.setRoles([1]).then(() => {
        res.send({message:"user was registered succefully!"})
    })}
  }).catch(err => {res.status(500).send({message: err.message})})
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!