sailsjs 0.11, node 0.12.4. with passport 0.2.1 and passport-local 1.0
Using the sailsjs blueprint routes just to see what's going on. The project is just a simple blog, and I tried looking at a user profile in the blueprint route /user/4
to show me userid 4. This message was the result.
Any ideas what caused this?
Note: i haven't been anywhere near sails/waterline source.
Full error message
/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/lib/waterline/model/lib/defaultMethods/toObject.js:59
throw err;
^
Error: There was an error turning the model into an object.
at new module.exports (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/lib/waterline/model/lib/defaultMethods/toObject.js:56:15)
at prototypeFns.toObject (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/lib/waterline/model/index.js:30:14)
at prototypeFns.toJSON (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/lib/waterline/model/index.js:112:20)
at Object.stringify (native)
at ServerResponse.res.json (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/express/lib/response.js:217:19)
at sendJSON (/home/vagrant/nodeprojs/<project>/api/responses/ok.js:34:23)
at viewReady (/home/vagrant/nodeprojs/<project>/api/responses/ok.js:72:25)
at viewFailedToRender (/home/vagrant/nodeprojs/<project>/node_modules/sails/lib/hooks/views/res.view.js:276:16)
at Function.app.render (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/express/lib/application.js:514:14)
at ServerResponse.res.render (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/express/lib/response.js:827:7)
at ServerResponse.res.view (/home/vagrant/nodeprojs/<project>/node_modules/sails/lib/hooks/views/res.view.js:237:16)
at Object.sendOK (/home/vagrant/nodeprojs/<project>/api/responses/ok.js:71:19)
at ServerResponse.bound [as ok] (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at found (/home/vagrant/nodeprojs/<project>/node_modules/sails/lib/hooks/blueprints/actions/findOne.js:37:9)
at wrapper (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/node_modules/lodash/index.js:3602:19)
at applyInOriginalCtx (/home/vagrant/nodeprojs/<project>/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:421:80)
And the User.js model. toJSON is commented out because the message originally pointed to that section. After commenting it out, line 3 (at User.attributes.toJSON
) is now different.
var bcrypt = require ('bcrypt')
var User = {
attributes: {
email: {
type: 'email',
required: true,
unique: true
},
password: {
type: 'string',
minLength: 6,
required: true
},
admin: {
type: 'boolean',
defaultsTo: false // separate from acl
},
acl: {
type: 'string',
defaultsTo: 'USER' // MOD, USER (unlogged should get GUEST)
}
/*
toJSON: function() {
var obj = this.toObject();
delete obj.password;
return obj;
}
*/
},
beforeCreate: function(user, cb) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(user.password, salt, function(err, hash) {
if (err) {
console.log(err);
cb(err);
} else {
user.password = hash;
cb();
}
});
});
}
};
module.exports = User;
[EDIT]
After further review, I did an object-to-string conversion and output it at several points. The object on the first line of a try
statement, and the first line of the subsequestn catch
statement is this:
waterline:toObject > this.object TRY=
>>>
email: [email protected]
password: $2a$10$bNktAvahfa3f8Q8lTV262u9RrLUqdvp7SzfM6dQqki3YliXdLMWxK
admin: true
acl: USER
createdAt: Fri May 29 2015 23:25:35 GMT+0000 (UTC)
updatedAt: Fri May 29 2015 23:25:35 GMT+0000 (UTC)
id: 1
_locals: [object Object]
<<<
+2ms
waterline:toObject > this.object CATCH=
>>>
email: [email protected]
password: $2a$10$bNktAvahfa3f8Q8lTV262u9RrLUqdvp7SzfM6dQqki3YliXdLMWxK
admin: true
acl: USER
createdAt: Fri May 29 2015 23:25:35 GMT+0000 (UTC)
updatedAt: Fri May 29 2015 23:25:35 GMT+0000 (UTC)
id: 1
_locals: [object Object]
<<<
(this output isn't supposed to be json, it's just a dump)