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

153
Visualizações
My bcrypt.js hash returns undefined while all other inputs are fine

This code below returns the input password as undefined, but all other inputs are fine. I don't know what to do, if anyone can help please do.

I am using bcrypt.js with knex for psql.

app.post("/register", (req, res) => {
  const { email, name, password } = req.body;
   let salt = bcrypt.genSaltSync(10);
   let hash = bcrypt.hashSync(password, salt);
  
   knex
     .transaction((trx) => {
       trx
         .insert({
           hash: bcrypt.hashSync(password, salt),
           email: email,
         })
         .into("login")
         .returning("email")
         .then((loginEmail) => {
           return trx("users")
             .returning("*")
             .insert({
               email: loginEmail[0].email,
               name: name,
               joined: new Date(),
             })
             .then((user) => {
               res.json(user[0]);
             });
         })
         .then(trx.commit)
         .catch(trx.rollback);
     })
     .catch((err) => res.status(400).json("E-mail is already in use"));
});

*P.S. Using postman gives no errors. The error that comes in on the back-end terminal is Error: Illegal arguments: undefined, string meaning hash is undefined

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I fixed it, was apparently a variable naming issue :) such a goof.

password was actually being received as "hash" from the front-end, changed it to hash & changed hash to hashedPassword.

  const { email, name, hash } = req.body;
  let salt = bcrypt.genSaltSync(10);
  let hashedPassword = bcrypt.hashSync(hash, salt);
  
  knex
    .transaction((trx) => {
      trx
        .insert({
          hash: hashedPassword,
          email: email,
        })
about 4 years ago · Juan Pablo Isaza 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