New session on every request
See original GitHub issueI’ve setup cookie-session exactly according to the instructions to test its work. But I get new session on every request: Here’s the initialization code:
app.use(cookieSession({
name: 'session',
keys: [Constants.COOKIE_SESSION_KEY_1, Constants.COOKIE_SESSION_KEY_2]
}));
app.use(function (req, res, next) {
req.sessionOptions.maxAge = 60000;
next();
})
And here’s the testing one:
router.get('/auth', function(req, res, next) {
console.log("SESSION BEFORE:", JSON.stringify( req.session), req.session.isNew);
res.json({ok: 'ok'})
req.session.test = 1;
console.log("SESSION AFTER:", JSON.stringify(req.session));
}
It always gives me this output:
SESSION BEFORE: {} true SESSION AFTER: {“test”:1}
I’m doing fetch() requests with credentials: ‘include’ option. I used client-sessions module before and it could set cookie
Am I missing anything?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
node.js - Express-session creates new session every request
I put my node express server into production. In development, express-session worked fine (it stored session into ...
Read more >Express creating new session for each request #330 - GitHub
Express-session is creating a new session (new sessionID) for new request. And it happens intermittently, for example sometimes for first ...
Read more >Laravel 5 creates a new session after each request - Laracasts
Hello I am working with the development version of Laravel 5 and I have a problem. If I try this: Session::set('hi', 'hello') dd(Session::get('hi'))...
Read more >Cookie problem in IIS7 and IE: New session id with ... - MSDN
Hi, I have a website running in IIS7 and it seems to be creating a new session for every request I make. The...
Read more >Cookie and Session (II): How session works in express-session
Session is created in server when the client send a request to it for the first time. There are different ways to create...
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
Hi @caseyryan weird, if I run only the code you provided above, where I just made my
login
functionsetTimeout
internally and then setup the most minimal Express around that route you gave as the only route, setting the session inside the callback did work fine. This means that the issue is somewhere between the minimal case I created and your full app. Since I can’t see any other code than what you posted above, I’m not sure what the difference is. Here is the app I made:And here is me trying to run it, getting the session cookie even with the async login call and the check validating it:
Ok, to be exact, I’ve made authorization for 2 Russian social networks vk.com and ok.ru. They both have standard OAuth2 authentication process for websites and third party applications which described here . My setup islike this: React-Redux frontend and Express backend api server. React is running on localhost:3000 and express is on localhost:3001. React proxies all requests to express. But as social network redirects a browser to ‘redirect_uri’ which I specify in my request to it and puts code and state params directly to the url, I can’t do it via proxy, so I’m doing this:
window.location.href = getLoginURL();
It forms the proper request URL to social network so that it could return code and state to my app which I can use for getting access_token from my server. And the problem starts exactly after I do this action. The SN responds with code and state params and also sets it’s own headers. After this I can’t set my own session until I reload the whole page and do my first fetch() request to my API server. If the first request would be to my API server instead of VK, Odnoklassniki or Twitter, the sessions will work like a charm