I have been using expressjs and mongostore for session management. Following is the code to configure store in expressjs,
app.configure(function(){ app.use(express.session({ secret: conf.secret, maxAge: new Date(Date.now() + 3600000), cookie: { path: '/' }, store: new MongoStore(conf.db) })); });
I had mentioned the cookie path in the above code. But it sets the cookie in sub.domain.com instead of .domain.com. How do i achieve this?
Please everyone note that you can set a cookie from a subdomain on a domain. But you CAN'T set a cookie from a domain on a subdomain.
Setting cookies for another domain is not possible. If you want to pass data to another domain, you can encode this into the url.
In order to correctly set cookies accessible on the client just use a snippet like the following: res. cookie('rememberme', 'yes', { maxAge: 900000, httpOnly: false});
configure it like this:
app.use(express.session({ secret: conf.secret, cookie: { domain:'.yourdomain.com'}, store: new MongoStore(conf.sessiondb) }));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With