问题
When I use login function
User.login({email: 'foo@bar.com', password: 'bar'}, function(err, accessToken) {
console.log(err);
console.log(accessToken);
})
the error is
TypeError: Object [Model session] has no method 'create'
回答1:
It looks like you are using an old version of LoopBack. Try upgrading and making sure the user model is attached to a data source. Below are the steps to do this.
// # Verify version
// Ω slc version
// slc v2.1.1 (node v0.10.9)
// # upgrade with `npm install strong-cli -g`
// # create a simple project
// Ω slc lb project hello-user
// Ω cd hello-user
// # create hello-user/models/user.js
var user = require('app').models.user;
var credentials = {
email: 'foo@bar.com',
password: 'password'
};
user.create(credentials, function(err) {
user.login(credentials, function(err, accessToken) {
console.log(accessToken);
// { userId: 1,
// ttl: 1209600,
// id: 'nt2KN4N5p3QbxByypRiHlduavxCRJUPbcStWPfxgrWYU8JllryjUp028hlJAFx4D',
// created: Tue Jan 14 2014 08:26:22 GMT-0800 (PST) }
});
});
来源:https://stackoverflow.com/questions/21115998/loopback-session-no-method-create