question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Session not saving

See original GitHub issue

I have a very simple application set up to test my session storage, and nothing is saving. Here’s the basic setup:

var sessionOptions = {
  key: 'session.sid',
  secret: 'Some secret key',
  resave: true,
  saveUninitialized: true,
  cookie: {
    secure: true,
    maxAge: 600000
  }
};

app.use(session(sessionOptions));

app.get('/user', function getUser(req, res, next) {
  console.log(req.session, req.session.user);

  if(!req.session.user) {
    req.session.user = { test: 'test' };
    res.status(403);
    return res.send('Not logged in');
  }

  res.send(req.session.user);
});

This should return a 403 status on the FIRST request only, but it’s returning a 403 every time I reload the page. Am I totally missing something?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
dougwilsoncommented, Oct 7, 2014

With secure: true option, you need to be accessing the site over HTTPS (i.e. not just http://localhost) AND you have to have express correctly configured (see https://github.com/expressjs/session#cookie-options). Your code is running fine for me when I met those requirements or removed secure: true.

4reactions
dougwilsoncommented, Oct 8, 2014

No problem! And as an additional tid-bit, if you set the environment variable DEBUG=express-session you’ll get some various messages on your console about what is going on in the module, though they are a little cryptic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP Session not Saving - Stack Overflow
session_save_path is defined in php.ini file. Probably in your testing server it is a folder writable by apache but in your server it...
Read more >
Fix: PHP sessions not saving. - This Interests Me
This is the most common cause of session data not saving. It is also the easiest to fix. Basically, PHP's session_start function MUST...
Read more >
PHP: My session variables are not being saved
Since the problem is about the session not being saved, the solution is to save the session before redirecting. How to do that?...
Read more >
PHP $_SESSION variable not saving across pages
I'm trying to save a SESSION variable and then print it onto another PHP file however the variable isn't saving across pages.
Read more >
Session variables not saving / persisting after redirect
Any idea why the session variables are not persisting?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found