title: Nestjs session not saving
body: <p>I am new to nestjs and started my first application today. I am trying to implement user login using express-session and connect-mongo to persist sessions even if my docker container gets killed or replaced.</p>
  <p>I have install <code>express-session</code> and <code>connect-mongo</code> and configured them in <code>main.ts</code></p>
  <pre><code>async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.use(
      session({
        secret: process.env.SECRET,
        resave: true,
        saveUninitialized: true,
        store: ConnectMongo.create({ mongoOptions: { useNewUrlParser: true, useUnifiedTopology: true }, mongoUrl: process.env.MONGO_URI, collectionName: 'loginsessions' }),
      }),
    );
    await app.listen(3000);
  }
  </code></pre>
  <p>I have created a login service that returns the details to set in session <code>uid</code> and <code>role</code></p>
  <pre><code>@Post('login')
    @HttpCode(HttpStatus.OK)
    async login(@_Session() session: Session, @Body() body: Pick&lt;UsersDto, 'email' | 'password'&gt;) {
      console.log(session.uid, session.role);
      if (session.uid) {
        return this.usersService.getId(session.uid);
      } else {
        const user = await this.usersService.login(body.email, body.password);
        session.uid = user._id;
        session.role = user.role;
        session.save();
        return { success: true, message: 'Logged in' };
      }
    }
  </code></pre>
  <p>Here are my two requests</p>
  <pre><code>$ curl -c cookie localhost:3000/users/login -XPOST -H &quot;Content-Type: application/json&quot; -d '{&quot;email&quot;: &quot;tbhaxor@gmail.com&quot;, &quot;password&quot;: &quot;test&quot;}'  &amp;&amp; echo
  {&quot;success&quot;:true,&quot;message&quot;:&quot;Logged in&quot;}
  $ curl -c cookie localhost:3000/users/login -XPOST -H &quot;Content-Type: application/json&quot; -d '{&quot;email&quot;: &quot;tbhaxor@gmail.com&quot;, &quot;password&quot;: &quot;test&quot;}'  &amp;&amp; echo
  {&quot;success&quot;:true,&quot;message&quot;:&quot;Logged in&quot;}
  </code></pre>
  <p>In application, accessing session values give me undefined</p>
  <p><a href="https://i.stack.imgur.com/92JkK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/92JkK.png" alt="enter image description here" /></a></p>
  <p>Also in DB, no session property <code>uid</code> or <code>role</code> is set</p>
  <p><a href="https://i.stack.imgur.com/MIuFO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MIuFO.png" alt="enter image description here" /></a></p>