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

160
Views
create a data validation using JOI module

I am new to Joi. I try to put some rules to signup users. But every new user could signup and "if" command is always executed.

const Joi = require ('joi')

const authSchema = Joi.object().keys({
email:Joi.string().email().required(),
password:Joi.string().min(10).max(24).required()
})

exports.email = (req,res,next) => { 
if(authSchema.validate(req.body)){
    console.log("je suis dans le middleware joi")
    console.log("-------> req.body")
    console.log(req.body)
    // authSchema.validate({email: req.body.email, password: req.body.password})
    // authSchema.validate(req.body)

    next()
} else{
    res.status(400).json({ error: "erreur de data validataion" });
    console.log("erreur ne convient pas a joi")
}

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hey use this is how i do main

validateInput(rowData) {
    const schema = Joi.object().keys({
      email: Joi.string().email().required(),
      firstName: Joi.string().required(),
      lastName: Joi.string().required(),
      contact: Joi.string().required(),
      roleId: Joi.number().allow("", null),
    });
    return schema.validate(rowData);
  },

And call it like this

    const { error } = await validateInput(user); // request body user.
        if (error) {
          return res.status(400).send({ message: error.details[0].message });
// it will return for you the message.
        }

Here is a link on how you can use Joi as a middleware. https://dev.to/tayfunakgc/middleware-based-joi-validation-in-expressjs-2po5

about 4 years ago · Juan Pablo Isaza Report
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!