Closed michaeljota closed 8 years ago
+1 Same here, I'm trying to set a property value in the preSave hook, but the changes are being lost.
preSave() {
this.slug = slugify(this.title); //this.title = 'some phrase'
console.log(this.slug); // 'some-phrase'
//mongodb = null
}
He is unable to work on it right now. But as soon as he can, he will look at it.
I just created a function to hash the password and called before the saving. It might work (It should at least, I hadn't try it).
It might work for you as well. :D
Update: It works!. Just use the function that make changes in the object and called before salving. :D.
Update2: I use password getter and setter to hash the password.
set password (password) {
this._password = password;
this.salt = this.makeSalt();
this.hashedPassword = this.encryptPassword(password);
}
get password () {
return this._password;
}
That solve my problem too, and it's easies to use, 'cause I just create the document with the 'password' param, and it actually hash the password, resulting:
{"name":"Test User","email":"test@test.com","hashedPassword":"(hashedPassword)","role":"user","provider":"local","salt":"(salt)","_id":"KNW4kT5nqj5cTg4V"}
+1 same issue.but I solved with stopgap. add single line code at line 138, node_modules/camo/lib/document.js
data = that._toData({_id:false}); line139: return DB().save(that.collectionName(), that._id, data);
data = that._toData({_id:false});
Can you add this please and release new version?
PRs! PRs for everyone!
I don't know if i'm doing this properly, but I'm trying to hash the password in either 'PreSave' or 'PostValidate' (I supposse PostValidate get's calling just before PreSave).
PostValidate got called, I think PreSave is not. But in either case, I doesn't make permanent changes to the document. The changes that are made, are lost when they get save.
The console outputs show they are being called. PostSave show changes in the document, but it the datastorage (I'm using NeDB) there is not salt in the document, and the password it's not hashed.
Any thoughs?
Thanks for camo. I don't think I ever got to post so much in a issue list, that is not mine own.
PS: I'm trying to using this with Passport, but all the examples are with 'mongoose'. I'm trying to write all the examples to camo, but I've fail, so far. Have you use Camo with Passport? How did you?