After update my sails (0.10-rc5),
I encountered a problem in beforeCreate function :
beforeCreate : function(values, next){
console.log("Called beforeCreate User ");
console.log(values);
if(!values.password || values.password !== values.confirmation){
return next({
err : ["Password doesn't match password confirmation"]
});
}
bcrypt.genSalt(10, function(err, salt){
console.log("call within bcrypt");
if (err) return next(err);
bcrypt.hash(values.password, salt, function(err, hash){
if(err) return next(err);
values.password = hash;
});
});
Access.findOne()
.where({ level : values.level })
.exec(function(err, level){
console.log("call within findOne");
if(err) return next(err);
values.level = level.id;
});
console.log("after");
console.log(values);
next();
}
However, the output of the above function is as following :
Called beforeCreate User
{ firstName: 'Quad',
lastName: 'Doe',
email: '11@11.com',
password: '123456',
confirmation: '123456',
level: 'admin',
id: '2fa1ba1a-ae1c-4380-9107-3c1f6e8eafb3',
online: false }
after
{ firstName: 'Quad',
lastName: 'Doe',
email: '11@11.com',
password: '123456',
confirmation: '123456',
level: 'admin',
id: '2fa1ba1a-ae1c-4380-9107-3c1f6e8eafb3',
online: false }
call within bcrypt
call within findOne
As you can see, somehow bcrypt.genSalt(.....){} and Access.findOne(...){} were not called prior to after, which is supposed to.