loopback session no method create?

。_饼干妹妹 提交于 2019-12-11 15:14:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!