Node.js承诺不返回对象

时间:2016-01-12 14:09:18

标签: javascript node.js promise bluebird

我正在编写一个验证模块,需要编写一个查询来返回一个用户数组(在我的authentication.js中。但是,当我在home.js中调用该函数时,该函数返回一个promise对象如:

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }

在我的代码片段中,我评论了我获取promise对象和用户数组的位置。

我的home.js

module.exports = function (req, res) {


var rawCookie = req.headers.cookie;


var result1 = Promise.resolve(authentication.authenticate(rawCookie))
    .then(function(result) {
        console.log(result); //returns the correct users array
        return result; 
    });

console.log(result1); //returns a promise object (should return the users array

};

我的authentication.js

exports.authenticate = Promise.method(function(rawCookie) { 
    var cookie = parseCookie.parseCookie(rawCookie);
    return knex('users')
        .where('session_key', cookie)
        .then(function(data){ 
            return data //returns array of users
    }); 
});

0 个答案:

没有答案
相关问题