0

I am writing an authentication module that needs to write a query to return an array of users (in my authentication.js. However, when I call the function in my home.js, the function returns a promise object like:

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

In my code snippet, I commented where I get a promise object and a users array.

My 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

};

My 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
    }); 
});
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
Trung Tran
  • 13,141
  • 42
  • 113
  • 200

0 Answers0