Session not saving
See original GitHub issueI 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:
- Created 9 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With
secure: true
option, you need to be accessing the site over HTTPS (i.e. not justhttp://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 removedsecure: true
.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.