title: Maintaining login session across subdomains in nodejs mongostore
body: <p>I'm developing a nodejs web application, in that I have multiple subdomains like domain.com, sub1.domain.com, sub2.domain.com etc. </p>
  
  <p>if user logs in to sub1.domain.com and gets redirected to domain.com or sub2.domin.com it will give as not logged in,</p>
  
  <p>How can I maintain this session across sub-domains and in main-domain?</p>
  
  <p>I'm using express, nodejs, mongodb.</p>
  
  <pre><code>app.use(session({
      secret: "secrete key",
      store: new MongoStore({
          db: "session-db"
      })
  }));
  </code></pre>
  
  <p>I tried setting up like this, didn't work:</p>
  
  <pre><code>app.use(session({
      secret: "secret key",
      cookie: { domain:'.yourdomain.com'}, // here I used '.localhost'
      store: new MongoStore({
          db: "session-db"
      })
  }));
  </code></pre>