so I basically want to use sessions to store the users name and check to see if the user logged in or not. If not, the page will redirect to the login page.
I am usi
If you're doing app.use(app.router)
before the lines that set up the cookie and session handling, try moving it to after them. That fixed the same problem for me.
the sessionSecret
in the configuration (config.json?) should be non-empty:
sessionSecret: "something other than an empty string",
I was trying to solve the exact same problem for he last few hour.
Try initializing your server like that:
var app = express.createServer(
express.cookieParser(),
express.session({ secret: "crazysecretstuff"})
);
That should work.
I had same issue of getting undefined for session variable which I knew was set ok.
In my case it turned out to be caused by cross origin request, I had forgotten the withCredentials header on the request.
So for example in my client side Angular app I needed to do this:
var config = { withCredentials: true };
return $http.get(appConfig.apiUrl + '/orders', config);
and in Express this:
res.header('Access-Control-Allow-Credentials', true);