slc loopback, use notes template, so it has auth system and User model
Attach User and auth related models to a cloudant datasource
In boot script, create a new user instance
Get error complains user is not valid
note: this won't happen if you already have the model's document in database.
Investigation:
setTimeout in boot script like the following code, give cloudant enough time to migrate model before creating user instance, problem solved.
'use strict';
module.exports = function(server) {
var User = server.models.User;
var doCreate = function() {
User.create({username: 'John', email: 'john@doe.com', password: 'opensesame'}, function(err, users) {
if (err) console.log(err);
console.log(users);
});
};
setTimeout(doCreate, 5000);
};
Reason
When create a new user, in validation function(juggler/lib/validation.js), it checks uniqueness first, therefore calls find(), which returns 500 error due to model migration not done
Reproduce:
slc loopback
, usenotes
template, so it has auth system andUser
modeluser
instanceInvestigation: setTimeout in boot script like the following code, give cloudant enough time to migrate model before creating user instance, problem solved.
Reason When create a new user, in validation function(juggler/lib/validation.js), it checks uniqueness first, therefore calls
find()
, which returns 500 error due to model migration not done