0

Waterline supports lifecycle callbacks (docs). My User model has:

beforeValidate: hash_password,
beforeCreate: hash_password,
beforeUpdate: hash_password

Which works fine for creating/updating records (I double checked in the database).

However on my findOne I always get a NotFoundError:

User.findOne({email: req.body.email, password: req.body.password}, (err, user) =>
                 cb(err ? err : !user ? new NotFoundError('User') : null)

Turning on database logging, I confirmed that the password in the findOne is never hashed.

What am I doing wrong?

A T
  • 13,008
  • 21
  • 97
  • 158
  • You need to explicitly hash password for `find*` methods. Replace `password: req.body.password` with `password: hash_password(req.body.password)`. (Assuming hash_password method works this way) – Sangharsh Apr 12 '17 at 06:59
  • Yeah, I was just changing my code to something similar. It's unfortunately that there's no lifecycle on `find` :( – A T Apr 12 '17 at 07:00
  • Yes. There is a discussion here: http://stackoverflow.com/q/28167738/1435132 – Sangharsh Apr 12 '17 at 07:03

0 Answers0