Can't set manual sessionID
See original GitHub issueSimilar to #148, I’m can’t seem to set a manual sessionID
. Setting it in signedCookies
like seems to be the solution doesn’t seem to work:
app
.use(function(req, res, next) {
if(req.query.sessionID) {
req.signedCookies["connect.sid"] = req.query.sessionID;
}
next();
})
.use(session({
httpOnly: false,
secret: 'secret',
resave: false,
saveUninitialized: true
})
.get('/session', function(req, res) {
console.log('sessionID:', req.sessionID);
req.session.tmp = req.session.tmp + 1 || 0;
req.session.save();
res.send('session: ' + req.session.tmp);
})
When I hit http://localhost:3000/session?sessionID=42
a couple of times, the counter goes up. When I hit that exact same url in a different browser I expect it to pick up the count from the session, but it does not.
An observation: The log for req.sessionID
is not what I gave to the query string, so I guess it’s initialising its own sessionID instead.
I’ve also tried a custom genid
like so:
.use(session({
httpOnly: false,
secret: 'secret42',
resave: false,
saveUninitialized: true,
genid: function(req) {
return req.query.sessionID || uuid.v1();
}
})
This seemed like a cleaner solution anyway, but it also doesn’t work for me. It sets the sessionID
correctly for the first hit, but it won’t update it for requests with a different sessionID
.
Any help on this would be great!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:17 (7 by maintainers)
Top GitHub Comments
Middleware configuration:
On successfull authentification:
really need to set the manual sessionID