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
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar

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 Denunciar
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