Reputation: 1618
I heard somewhere that I can use a property in the req object called sessionID
but when I used it, it was undefined. The property is not set. Is there a way to uniquely identify a client without using express's session? Because it would require me to rewrite my whole back-end.
router.post('/signup', function(req, res) {
console.log(req)
var signup = auth.signup(req.body.un, req.body.email, req.body.pw, req.body.pc, req.sessionID);
if (signup !== 1) {
res.render("signup", { title, err: signup })
} else {
res.redirect("/dashboard")
}
})
Upvotes: 1
Views: 217
Reputation: 4164
req.sessionID
is a custom field added to the req object via middleware, in some cases this would be via express-session
but you could attach it in anyway you want. For example, you could create some middleware which reads a cookie or header value, extracts what you define as the session id, and attaches it to the req object directly.
If you're using some other sort of authentication then this should be fairly trivial to introduce a piece of middleware to translate this over. However you have no authentication built at the moment, then you won't have the data to make this work.
Upvotes: 1