无法读取Node.js中未定义的属性'then'

PPS*_*ein 1 javascript node.js express passport.js

我不知道为什么我在代码中遇到该错误。

    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;
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

Vik*_*rba 5

您应该添加return before auth.findOne第二个原始文件。

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