Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!