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

191
Vistas
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 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