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

227
Views
Delete password from sequelize model

i'm learning Sequelize and i see something weird in the course,

const { Strategy } = require('passport-local');
const boom = require('@hapi/boom');
const bcrypt = require('bcrypt');

const UserService = require('./../../../services/user.service');
const service = new UserService();

const LocalStrategy = new Strategy({
    usernameField: 'email',
    passwordField: 'password'
  },
  async (email, password, done) => {
    try {
      const user = await service.findByEmail(email);
      if (!user) {
        done(boom.unauthorized(), false);
      }
      const isMatch = await bcrypt.compare(password, user.password);
      if (!isMatch) {
        done(boom.unauthorized(), false);
      }
      delete user.dataValues.password;
      done(null, user);
    } catch (error) {
      done(error, false);
    }
  }
);

module.exports = LocalStrategy;

My question is, when I want to compare passwords I use

bcrypt.compare(password, user.password);

and when I want to delete the password I use

delete user.dataValues.password

where does dataValues ​​come from, by the way I'm using sequelize

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I don't recommend to delete service props in Sequelize model (dataValues prop holds metadata about all fields of a certain model) because it can lead to incorrect work of this model. Instead of deleting the password field form dataValues you need to delete it from a plain object that represents a certain model instance:

const { password, ...plainUser } = user.get({ plain: true })

done(null, plainUser);
over 4 years ago · Santiago Trujillo 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!