0

Good afternoon, everyone. I have a database with users' secret information. I want to disable returning of column "password" when I use findOne(). How can I do it without deleting it from the response object?

MuffinColor
  • 21
  • 1
  • 5

2 Answers2

0

If you want to return all the fields except one, you can use the exclude attribute like this :

    myTable.findOne({
        attributes: {exclude: ['password']},
        where: { id: userId }
    })
gduh
  • 1,079
  • 12
  • 30
0

you could do that while defining your schema by using toJson it allows you to edit your returned schema like this

sequelize.define('user', attributes, {
  instanceMethods: {
    toJSON: function () {
      const values = Object.assign({}, this.get());

      delete values.password;
      return values;
    }
  }
});
Joseph
  • 5,644
  • 3
  • 18
  • 44