2016-01-21 60 views
0

我不知道爲什麼我在代碼中遇到錯誤。無法讀取nodejs中未定義的屬性'then'

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

回答

3

您應該在第二個原始中添加return before auth.findOne

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

您可以更新我的代碼的答案嗎? – ppshein

2

應該 return auth.findOne(...

相關問題