Reputation: 599
I am trying to implement a webpage with node.js using hbs engine and express framework... after login i m trying to catch cookies and check in one page as authentication.
app.get('/path', function (req, res) {
var cookie= req.cookies.UserId;
if (cookie != ''||cookie !=null)
{
//doing somethig
}
else
{
res.redirect("some url");
}
}
but when i m giving direct url without login this condition get failed and it is not checking for cookies. Initialy cookie is null only still it is failed to redirect..what is the solution for this?
Upvotes: 0
Views: 59
Reputation: 1108
Before u redirect try to set maxAge as your domain with your cookie.
Then
var cookie= req.cookies.UserId;
Example Refer Set cookie
http://expressjs.com/api.html#res.cookie
Take cookie Refer
http://expressjs.com/api.html#req.cookies
Upvotes: 1