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

194
Views
Password reset not saving to database

My code above runs without any errors but the new password isn't saved.

I've been following the bcrypt docs, a blog post and a video and think the three different sources have resulted in my missing something critical. Any ideas why the new password isn't being saved?

module.exports.submitNewPassword = async (req, res) => {
    const slidedHeaderToken = req.headers.referer.slice(-40);
    const artist = await Artist.find({ resetPasswordToken: slidedHeaderToken, resetPasswordExpires: { $gt: Date.now() } });
    if (!artist) {
        console.log("Artist doesn't exist");
    } else {
        const hashedPassword = async (pw) => {
            bcrypt.hash(req.body.password, 12)
        }
        hashedPassword()
        artist.password = hashedPassword;
        resetPasswordToken = null;
        resetPasswordExpires = null;

        console.log("Successfully resubmitted password");
        res.redirect('login');
    }
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You should call await artist.save() function after you set some fields

about 4 years ago · Juan Pablo Isaza Report

0

When you make a change to the data using FindOne, you need to save it.

await yourVariable.save()
about 4 years ago · Juan Pablo Isaza Report

0

artists is an array of all the artists matching the parameters in the call to .find(). If you just want to find one, use .findOne().

Then after you modify it, use .save() to save it back to the database.

module.exports.submitNewPassword = async (req, res) => {
    const slidedHeaderToken = req.headers.referer.slice(-40);
    const artist = await Artist.findOne({ resetPasswordToken: slidedHeaderToken, resetPasswordExpires: { $gt: Date.now() } });
    if (!artist) {
        console.log("Artist doesn't exist");
    } else {
        const hashedPassword = async (pw) => {
            bcrypt.hash(req.body.password, 12)
        }
        hashedPassword()
        artist.password = hashedPassword;
        await artist.save();
        resetPasswordToken = null;
        resetPasswordExpires = null;
        console.log("Successfully resubmitted password");
        res.redirect('login');
    }
}

See the Mongoose tutorial here.

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