How do I prevent multiple browser windows from sharing the same session in node.js?

2.3k views Asked by At

Is there any way to prevent the multiple browser windows from sharing the same session using Connect and redis DB? I have gone through the link Working with Sessions in Express.js. But this is implemented with Express. I want the similar goal to be implemented with Connect.
Any help on this will be really helpful.

2

There are 2 answers

0
Ivan Plenty On

Most modern browsers have a shared pool for cookies, which is how express typically manages sessions. Different browser windows are just using the same cookies, and the issue lies with how browsers work.

I would recommend one of two options:

  1. Use the privacy mode (incognito in Chrome) in your browser to get a second pool of cookies.
  2. Use a second browser (have both Firefox and Chrome installed)
0
ragamufin On

It would help if you were to specify more about what you are trying to do and maybe even why. By multiple browser windows I assume you mean in the same browser. As @Ivan Plenty said, browser windows/tabs all share cookie information and that's pretty much standard. The only way to get away from that is to use the various incognito modes of each browser.

That said, if you want a way to specifically create sessions per window or to distinguish between windows then you could employ a scheme of passing a csrf token around. Normally this is used for security reasons but you could tailor it to your needs. Have a look here for Connect's csrf.