3

I'm having trouble getting a cookie to be passed back with an Express.js response. The situation is that I'm making an XHR containing user credentials, checking if the user exists, if the user does exist and credentials are correct I store the users info in Redis via node_redis. In the callback that I hand Redis I create a cookie on the response object, then send the customer object to the browser.

Here is the Redis code (note: I'm not using Express sessions so I just added the Redis client into req.session via middleware):

req.session.hmset('user', customer, function(err, status) {
    res.cookie('sid', 'sessionID', {
        maxAge: 3600000,
        path: '/',
        httpOnly: false
    });
    res.send(customer);
});

The odd thing is that when I add a console.log(res._headers); right after creating the cookie, there is a 'set-cookie' header present, but it never makes it to the browser. Might I have bad request headers? Something else? I'm completely stumped here...

4

0 回答 0