Reputation: 5016
I'm making a request to my Node.js server using the Postman plugin for Chrome. In my headers I have a field called Cookie and it's populated with my AuthSession cookie like so:
AuthSession="somekeyhere";
I've tried using a Set-Cookie field as well, to be honest I don't really know the difference between the two.
Here is my code that's supposed to receive the cookie, but it doesn't seem to be working.
exports.add = function(req, res) {
console.log(req.cookies['AuthSession']);
}
It keeps logging undefined. Obviously I'm doing something wrong, I'm just not sure what.
Upvotes: 0
Views: 271
Reputation: 38849
Verify first that setting cookies is working. Use the function below and load it twice. First time it'll show you your existing cookie. Second time it'll show you the cookie it set the first time.
exports.add = function(req, res) {
console.log(req.cookies['AuthSession']);
res.cookie('AuthSession', 'somekeyhere');
res.send("<html><body>Hello world</body></html>");
}
Upvotes: 1