2

We are working on express node.js application in which we are using 2 subdomain e.g. app.example.com & blog.example.com Both applications are running on same server with different port.

We are using express-session, when someone login's into app.example.com, a new cookie I created in the browser and all things are working fine with that particular domain, but when the user opens blog.example.com it was unable to use the same cookie and rather creates a new one for blog.example.com.

We have tried all possibilities with parameters for the cookie:{domain:".example.com"}. We have also used CORS to set headers.

We have checked Sharing Redis Sessions Across Node Apps and Share sessions with redis and passport on a subdomain? for defining the domain with ".example.com" but it's not working.

Is there anything which we are missing?

Code

app.use(function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
 genid =req.cookies['connect.sid'] ? req.cookies['connect.sid'] : "";


 next();
 });


 app.use(session({ secret: 'XXXX',resave: true,saveUninitialized: false, 
 store:sessionStore, cookie:{domain:".example.com",sameSite:false}}));
MANISHDAN LANGA
  • 2,227
  • 6
  • 29
  • 43
  • 1
    You need to share some code here, there are a lot of things you're possibly missing. Also, have you verified that the cookie isn't being sent, or is that an assumption? – Paul Sep 14 '17 at 11:46
  • @Paul, thanks for the reply, updated code on post, please check it. – MANISHDAN LANGA Sep 14 '17 at 12:28

0 Answers0