2016-03-31 72 views
1

我在我的服務器終端中獲取[object,Object]而不是整個用戶數據。我不知道這是什麼意思......我認爲我做得很完美,但仍然無法獲得全部數據。我指定了sailjs服務器。 如何獲取整個用戶數據而不是[object,Object]?獲取[object,Object]而不是整個用戶數據。那是什麼意思?

module.exports = { 
    /** 
    * Check the provided email address and password, and if they 
    * match a real user in the database, sign in to Medool. 
    */ 
    login: function (req, res) { 

    // Try to look up user using the provided email address 
    User.findOne({ 
     email: req.param('email') 
    }, function foundUser(err, user) { 

     if (err) 
     return res.negotiate(err); 
     if (!user) 
     return res.notFound(); 

     // Compare password attempt from the form params to the encrypted password 
     // from the database (`user.password`) 
     require('machinepack-passwords').checkPassword({ 
     passwordAttempt: req.param('password'), 
     encryptedPassword: user.encryptedPassword 
     }).exec({ 
     error: function (err) { 
      return res.negotiate(err); 
     }, 
     /* 
     If the password from the form params doesn't checkout w/ the encrypted 
     password from the database... 
     */ 
     incorrect: function() { 
      return res.notFound(); 
     }, 
     success: function() { 

      // Store user id in the user session 
      console.log("User form the login check" +user) 

      req.session.me = user.helpsterId; 
      console.log(req.session.me); 

      // All done- let the client know that everything worked. 
      return res.ok(); 
     } 
     }); 
    }); 

    } 

}; 

Output when lifted server is [object, Object]in console

+1

查看http://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-js-console-log-rather-than-object – cl3m

+0

這就是你得到的當你連接一個字符串和一個對象時,試着做'console.log(「用戶形成登錄檢查,用戶)'而不是看對象 – adeneo

+0

一個調用javascript對象的'toString'評估爲''[object Object]」 ' – Akshay

回答

4

試試吧,

console.log(user); 
console.log(JSON.stringify(user)); 
console.log("User form the login check" +user); 

,併爲我們寫的結果。

+0

{helpsterId:1, 姓: '比爾', 名字: '蓋茨', 手機:9560644561, 電子郵件:'[email protected] ', encryptedPassword:'$ 2a $ 10 $ gezlHKlHZniBugT4MhXlDeWm1yR6S656eMIssTxssGcoh4A/HbZKu', 性別:'男性', 在線:真實, 管理:真實, DOB: '2012-03-20T18:30:00.000Z', } –

+0

用戶表單登錄檢查[對象的對象] –

+0

非常感謝budy –

相關問題