Search code examples
htmlnode.jsexpresssession-variables

Req.session variable is always false


I dont know why but req.session.notf_logged in client side is always false... On server side it is true.

Req.session in server console:

Session {
  cookie: {
    path: '/',
    _expires: 2020-04-11T03:30:27.725Z,
    originalMaxAge: 2592000,
    httpOnly: true
  },
  err_not_logged: false,
  loggedin: true,
  notf_logged: true
}

Client side:

if(${req.session.notf_logged})
  console.log("notf_logged");
else
  console.log("notf_logged false");

Solution

  • The session data is only stored at the server and it cant be accessed from the client. In the client only is stored a cookie (generally http only) with a unique identifier that is used by the server to identify the "session" associated with the request.