Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
Express-validator returning empty array of erros even when there are errors

I am trying to validate user input with express validator and I get an empty array of errors which is incorrect because I sent the wrong input to test. When I console.log(errors), I get this : Result { formatter: [Function: formatter], errors: [] }

login = async (req, res) => {
  try {
    body("email").isEmail(), body("password").isLength({ min: 5 });
    const errors = validationResult(req);
    console.log(errors);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    const user = await User.findOne({ where: { email: req.body.email } });
    if (!user) {
      return res
        .status(400)
        .json({ error_msg: "An account for this email does not exist" });
    }
    const validPass = await bcrypt.compare(req.body.password, user.password);
    if (!validPass) {
      return res.status(400).json({ error_msg: "E-mail or password is wrong" });
    }
    const token = await getSignedToken(user);
    return res.status(200).json({ token: token });
  } catch (error) {
    return res.status(400).json({ error_msg: error.message });
  }
};

This is my sample input: { "email":"samadejoro", "password":"sams" }

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda