我已使用基本用户创建了自定义用户,并且我正在搜索以下电子邮件是否存在于db中,如果电子邮件存在,则不要创建它并记录访问令牌。
module.exports = function (User) {
let app = require('../../server/server');
var loopback = require('loopback');
var credentials = { email: 'foo@foo.com', password: 'password' };
var filter = {
'where': {
'email': credentials.email
}
};
loopback.User.findOrCreate(filter, credentials, function (err) {
if (err) throw err;
User.login(credentials, function (err, token) {
if (err) throw err;
console.log(token);
process.exit();
});
});
Error:
Error: Cannot call User.findOrCreate(). The findOrCreate method has not been setup. The PersistedModel has not been correctly attached to a DataSource!
答案 0 :(得分:0)
尝试检查您的数据源配置,看看它是否已正确连接到数据库。
答案 1 :(得分:0)
只需尝试
User.findOrCreate(filter, credentials, function (err) { });
如回送文档
PersistedModel.findOrCreate([filter], data, callback)
参考链接:https://apidocs.strongloop.com/loopback/#persistedmodel-findorcreate