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

196
Visualizações
Unable to encrypt password when updating bcrypt?

I want to update a customer's information that consists of first name, last name, email and password. I want to encrypt the password when its being updated. I wrote my route like this:

customerRouter.put(
    '/:id', isAuth,
    expressAsyncHandler( async (req, res) => {
    const {id} = req.params;
    const customer = await Customers.findOne({where: {id: id}});
    const {firstname,lastname,password,email} = req.body;

    if (!customer) {
        res.status(401).send({
            message: "Customer Not Found",
        });
    }else{
        bcrypt.hash(password,10).then((hash)=>{
            customer.firstName = firstname || customer.firstName
            customer.lastName = lastname || customer.lastName
            customer.email = email || customer.email
            customer.password = hash || customer.password
        })
        const updatedCustomer = await customer.save(); 
        res.send({
            id: updatedCustomer.id,
            firstname: updatedCustomer.firstName,
            lastname: updatedCustomer.lastName,
            email: updatedCustomer.email,
            isAdmin: updatedCustomer.isAdmin,
            token: generateToken(updatedCustomer)
        });
    };
})
);

The password wont change in the backend, I had a previous method that didn't encrypt and only changed the password, but this one doesn't encrypt the password or change it. Any help/guidance is much appreciated.

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