title: How to keep the session active when redirecting from domain to subdomain in Express js/
body: <p>I am working on an Express project(MEAN). i have my login/register page at myDomain.com and on login i want to redirect the user to user.myDomain.com . I am storing the session in MongoDb using session storage module. I can redirect the user to the subdomain but since the session is not maitained in between the domain and subdomain.. it redirects user to the login page.
  I have looked and tried everything from </p>
  
  <p><a href="https://stackoverflow.com/questions/9071969/using-express-and-node-how-to-maintain-a-session-across-subdomains-hostheaders">Using Express and Node, how to maintain a Session across subdomains/hostheaders</a>
  <a href="https://github.com/jaredhanson/passport/issues/125" rel="nofollow noreferrer">https://github.com/jaredhanson/passport/issues/125</a>
  <a href="https://stackoverflow.com/questions/28626058/maintaining-login-session-across-subdomains-in-nodejs-mongostore">Maintaining login session across subdomains in nodejs mongostore</a></p>
  
  <p>But i am still lost and could not find a proper solution for thise.
  Can you please help me.</p>
  
  <p><strong>Edit:</strong>
  I did this but id did not help me.</p>
  
  <pre><code>app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cors());
  app.use(cookieParser());
  app.use(express.static('../app'));
  
  app.use(session({
    secret:appConfig.SECRET,
    resave:false,
    saveUninitialized:true,
    domain: '.myDomain.com',
    store: sessionstore.createSessionStore({
        type: 'mongodb',
        host: 'localhost',         // optional
        port: 27017,               // optional
        dbName: 'MyDataBase',       // optional
        collectionName: 'sessions',// optional
        timeout: 10000             // optional
        // authSource: 'authedicationDatabase',        // optional
        // username: 'technicalDbUser',                // optional
        // password: 'secret'                          // optional
        // url: 'mongodb://user:pass@host:port/db?opts // optional
    }),
    cookie: {
           path: '/',
           domain: '.myDomain.com',
           maxAge: 1000 * 60 * 24 // 24 hours
       }
  }));
  </code></pre>