无法读取 nodejs 中未定义的 属性 'then'

Cannot read property 'then' of undefined in nodejs

我不知道为什么我在我的代码中遇到了那个错误。

    fineOneBySocialLogin(profile).then(function (user) {

    }, function (err) {
        return done(err, null);
    })



var fineOneBySocialLogin = function (req, res) {
    auth.findOne({ username: req.emails[0].value }).then(function (user) {
        if (!user) {
            console.log('testing 1');
            var userForm = {};
            userForm = {
                email: req.emails[0].value
            };
            user.createUser(userForm).then(function(user) {
                if (user) {
                    console.log('testing 2');
                    auth.findOne({ username: req.emails[0].value }).then(function (user) {
                        if (user) {
                            console.log('testing 3');
                            return user;
                        }
                    });
                }
            });
        } else {
            return user;
        }
    });
}

你应该在第二个原始文件中添加return before auth.findOne

var fineOneBySocialLogin = function (req, res) {
  return  auth.findOne({ username: req.emails[0].value }).then(...

应该是 return auth.findOne(...