title: Express-session does not set cookie?
body: <p>I'm following along with <a href="https://www.youtube.com/watch?v=I6ypD7qv3Z8&amp;t=8743s" rel="nofollow noreferrer">Ben Awad's 13-hour Fullstack React GraphQL TypeScript Tutorial</a> and encountered a wall during the login cookie setting (aprx at 1:50:00).</p>
  <p>I think I successfully connected to redis, set express-session and set req type but in graphql sandbox I don't see my cookie (named 'qid') at Inspect-&gt;Application.</p>
  <p>index.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { MikroORM } from &quot;@mikro-orm/core&quot;;
  import { __prod__ } from &quot;./constants&quot;;
  import microConfig from &quot;./mikro-orm.config&quot;;
  import express from &quot;express&quot;;
  import { ApolloServer } from &quot;apollo-server-express&quot;;
  import { buildSchema } from &quot;type-graphql&quot;;
  import { HelloResolver } from &quot;./resolvers/hello&quot;;
  import { PostResolver } from &quot;./resolvers/post&quot;;
  import { UserResolver } from &quot;./resolvers/user&quot;;
  import redis from &quot;redis&quot;;
  import session from &quot;express-session&quot;;
  import connectRedis from &quot;connect-redis&quot;;
  
  const main = async () =&gt; {
    const orm = await MikroORM.init(microConfig);
    await orm.getMigrator().up();
  
    const app = express();
  
    const RedisStore = connectRedis(session);
    const redisClient = redis.createClient();
  
    app.use(
      session({
        name: &quot;qid&quot;,
        store: new RedisStore({
          client: redisClient,
          disableTouch: true,
        }),
        cookie: {
          maxAge: 1000 * 60 * 60 * 24 * 365 * 10,
          httpOnly: true,
          sameSite: &quot;none&quot;,
          // secure: __prod__,
        },
        saveUninitialized: false,
        secret: &quot;dfhfdjkgfkbjktzkzf&quot;,
        resave: false,
      })
    );
  
    app.use(function (req, res, next) {
      res.header(
        &quot;Access-Control-Allow-Origin&quot;,
        &quot;https://studio.apollographql.com&quot;
      );
      res.header(&quot;Access-Control-Allow-Credentials&quot;, &quot;true&quot;);
      next();
    });
  
    const apolloServer = new ApolloServer({
      schema: await buildSchema({
        resolvers: [HelloResolver, PostResolver, UserResolver],
        validate: false,
      }),
      context: ({ req, res }) =&gt; ({ em: orm.em, req, res }),
    });
  
    await apolloServer.start();
    apolloServer.applyMiddleware({
      app,
      cors: {
        credentials: true,
        origin: new RegExp(&quot;/*/&quot;),
      },
    });
  
    app.listen(4000, () =&gt; {
      console.log(&quot;server started on port 4000&quot;);
    });
  };
  
  main();
  
  </code></pre>
  <p>types.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { EntityManager, IDatabaseDriver, Connection } from &quot;@mikro-orm/core&quot;;
  import { Request, Response } from &quot;express&quot;;
  import { Session, SessionData } from &quot;express-session&quot;;
  
  export type MyContext = {
    em: EntityManager&lt;any&gt; &amp; EntityManager&lt;IDatabaseDriver&lt;Connection&gt;&gt;;
    req: Request &amp; {
      session: Session &amp; Partial&lt;SessionData&gt; &amp; { userId: number };
    };
    res: Response;
  };
  
  </code></pre>
  <p>and my userResolver (user.ts)</p>
  <pre class="lang-js prettyprint-override"><code>import { User } from &quot;../entities/User&quot;;
  import { MyContext } from &quot;../types&quot;;
  import {
    Arg,
    Ctx,
    Field,
    InputType,
    Mutation,
    ObjectType,
    Query,
    Resolver,
  } from &quot;type-graphql&quot;;
  import argon2 from &quot;argon2&quot;;
  
  @InputType()
  class UsernamePasswordInput {
    @Field()
    username: string;
  
    @Field()
    password: string;
  }
  
  @ObjectType()
  class FieldError {
    @Field()
    field: string;
  
    @Field()
    message: string;
  }
  
  @ObjectType()
  class UserResponse {
    @Field(() =&gt; [FieldError], { nullable: true })
    errors?: FieldError[];
  
    @Field(() =&gt; User, { nullable: true })
    user?: User;
  }
  
  @Resolver()
  export class UserResolver {
  
  
    @Mutation(() =&gt; UserResponse)
    async login(
      @Arg(&quot;options&quot;, () =&gt; UsernamePasswordInput) options: UsernamePasswordInput,
      @Ctx() { em, req }: MyContext
    ): Promise&lt;UserResponse&gt; {
      const user = await em.findOne(User, { username: options.username });
      if (!user) {
        return {
          errors: [
            {
              field: &quot;username&quot;,
              message: &quot;username does not exist&quot;,
            },
          ],
        };
      }
      const valid = await argon2.verify(user.password, options.password);
      if (!valid) {
        return {
          errors: [
            {
              field: &quot;password&quot;,
              message: &quot;incorrect password&quot;,
            },
          ],
        };
      }
  
      req.session.userId = user.id;
  
      return {
        user,
      };
    }
  }
  
  </code></pre>
  <p>I tried setting up res.headers as graphql sandbox is asking but still to no avail. Would appreciate any help, thank you!</p>