title: Sessions Across Subdomains in Express
body: <p>I'm using the vhost feature in Express with Node to manage multiple subdomains for my app. The app uses the same session secret and key, and I believe I've used the correct session cookie settings:</p>
  
  <pre><code>cookie: {
            path     : '/',
            domain   : '.example.com',
            httpOnly : false,
            maxAge   : 1000*60*60*24*30*12    //one year(ish)
          }
  </code></pre>
  
  <p>I set a session variable on my regular site where the subdomain is undefined e.g. <a href="http://example.com" rel="nofollow noreferrer">http://example.com</a> like so:</p>
  
  <pre><code>req.session.rep_id = rep._id;
  res.redirect('https://' + company.name + '.example.com/');
  </code></pre>
  
  <p>But when I redirect them to subdomain.example.com the session doesn't have the rep_id key set to anything. It seems like the session is getting reset between subdomains. How do I get around this?</p>