Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
Express Custom Validator always returning Error

This is part of my login API used to validate the new user details. The function ifIDAlreadyExist checks the DB and returns true/false for exists/not exists respectively.

Even when the result is false, the error message is returned with the below code. What's wrong with this?

const RegInputValdiationRules = () => {
  return [
    check("id")
      .not()
      .isEmpty()
      .withMessage("Please enter the login id")
      .custom((value) => {
        ifIDAlreadyExist(value).then((exists) => {
          console.log(exists);
          if (exists === true) return Promise.reject("");
          else return true;
        });
      })
      .withMessage("ID already exists"),
    check("password")
      .not()
      .isEmpty()
      .isLength({ min: 6 })
      .withMessage("Password should contain at least six characters"),
  ];
};

enter image description here

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you're missing return within custom method:

const RegInputValdiationRules = () => {
  return [
    check("id")
      .not()
      .isEmpty()
      .withMessage("Please enter the login id")
      .custom((value) => {
        return ifIDAlreadyExist(value).then((exists) => {
          console.log(exists);
          if (exists === true) return Promise.reject("");
          else return true;
        });
      })
      .withMessage("ID already exists"),
    check("password")
      .not()
      .isEmpty()
      .isLength({ min: 6 })
      .withMessage("Password should contain at least six characters"),
  ];
};
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda