简体   繁体   中英

Cannot read property 'then' of undefined in nodejs

I have no idea why I encountered that error in my code.

    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;
        }
    });
}

You should add return before auth.findOne in the second raw.

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

应该return auth.findOne(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM