Reputation:
I'm working with this boilderplate https://github.com/sahat/hackathon-starter, which is using express-session, mongostore, for user session management.
The node document created for each session looks like this:
{
"_id": "QDKVO5GM6GrNYd0SlQyTgJsx",
"session": "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"535e005c02d3c0ed79463583\"},\"_csrfSecret\":\"MqLJJ8qZLSk5/w==\",\"returnTo\":\"/\",\"flash\":{}}",
"expires": {
"$date": "2014-05-12T08:27:04.696Z"
}
}
Is there a way that I can add data to each session? The goal here is to use the session data to store products in a cart.
Thanks,
Upvotes: 1
Views: 821
Reputation: 106736
Just attach objects/values to your req.session
object and they will be saved at the end of the response.
Upvotes: 0
Reputation: 14975
You can add properties, and therefore data, to the session variable in the same way that you can to any Javascript object.
If you're using express-session
then you have access to the req.session
variable so you can store a data object using
req.session.data = data;
and it will be available as long as the session remains alive.
Upvotes: 1