0

I am having a problem with sessions across sub-domains

I use connect mongo like so:

app.use(session({ // req.session is populated
        secret: 'xxxxxx',
        saveUninitialized: true,
        resave: true,
        store: new MongoStore({
            db: 'nnn'
        }),
        cookie: {
            path: '/',
            maxAge: new Date(Date.now() + time),
            domain : 'mydomain.com' ,
            httpOnly: true
        }
    }));

However, when I redirect to a subdomain xyz.mydomian.com the session is invalidated. Can anyone recommend a strategy for getting cross domain login to work with connect-mongo ?

avrono
  • 1,648
  • 3
  • 19
  • 40
  • This is less an issue of connect-mongo, but more an issue of using the same session in different domains. The Mongo store is using the session id to look up relevant data on every request. If you want that data to be also available on a different domain, you might want to pass the session id to the new server on redirect. – Amberlamps Nov 10 '14 at 09:31
  • Also, have a look at that question: http://stackoverflow.com/questions/24241964/setting-a-domain-on-the-default-connect-sid-browser-cookie-in-an-express-app – Amberlamps Nov 10 '14 at 09:39

0 Answers0