title: I can't set the SameSite attribute of the cookie to None in Nodejs (Express)
body: <p>We are creating a backend for a Twitter view app in Nodejs (Express).</p>
  <p>I'm thinking of using Twitter Api for login and storing the token returned after authentication to the session and then restoring the session from the cookie when it is accessed again.</p>
  <p>However, the cookie is blocked when it is accessed again and I can't restore the session information.</p>
  <p>The browser I use is chrome, but since chrome version 80, SameSite attribute seems to be Lax (sends a cookie when called from the site of the same domain) when the SameSite attribute is not specified, and in this case, front and back end are different domains, so cookies are blocked.</p>
  <p>So I am trying to set the SameSite attribute to None (sends a cookie when called by any site), but I can't seem to set it well and asked this question.</p>
  <p>I'm wondering if I can set the SameSite attribute to None if I make a difference in the part of app.use(session({})), but...</p>
  <p>If anyone knows of a solution, I would appreciate your help.</p>
  <p>Thank you for your help.</p>
  <h3>The corresponding source code</h3>
  <pre><code>callback_url = env.URL + &quot;oauth/callback&quot;;
  
  app.use(
      cookieSession({
        name: &quot;session&quot;,
        keys: [&quot;thisappisawesome&quot;],
        maxAge: 24 * 60 * 60 * 100
      })
  );
  
  app.use(cookieParser());
  
  // Save to session
  passport.serializeUser(function(user, done) {
      done(null, user.id);
  });
  
  // Restore from Session
  passport.deserializeUser(function(user, done) {
      done(null, user);
  });
  
  passport.use(
      new TwitterStrategy({
          consumerKey: env.TWITTER_CONSUMER_KEY,
          consumerSecret: env.TWITTER_CONSUMER_SECRET,
          callbackURL: callback_url
      },
      async (token, tokenSecret, profile, done) =&gt; {
  
          return done(null, profile);
      }
  ));
  
  app.use(session({
      allowedHeaders: ['sessionId', 'Content-Type'],
      exposedHeaders: ['sessionId'],
      secret: 'reply-analyzer',
      resave: false,
      saveUninitialized: false
  }));
  
  var cors_set = {
      origin: env.CORS_ORIGIN_URL,
      methods: &quot;GET,HEAD,PUT,PATCH,POST,DELETE&quot;,
      credentials: true // allow session cookie from browser to pass through
  };
  
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(cors(cors_set));
  
  </code></pre>
  <h3>What I've tried.</h3>
  <p>1.I tried setting the cookie options in the app.use(session({})) part, but it was not possible to set the SameSite attribute to None.</p>
  <pre><code>app.use(session({
      allowedHeaders: ['sessionId', 'Content-Type'],
      exposedHeaders: ['sessionId'],
      secret: 'reply-analyzer',
      resave: false,
      saveUninitialized: false,
      cookie : {
          secure: true,
          sameSite: 'None'
        }
  }));
  </code></pre>
  <p>2.I tried using the following middleware (<a href="https://github.com/krakenjs/express-samesite-default" rel="noreferrer">express-samesite-default</a>), but the SameSite attribute can be set to None, and the It wasn't.</p>
  <pre><code>var sameSiteCookieMiddleware = require(&quot;express-samesite-default&quot;);
  
  app.use(sameSiteCookieMiddleware.sameSiteCookieMiddleware());
  
  </code></pre>
  <h3>Additional information</h3>
  <p>Node.js v12.18.2
  chrome v84.0.4147.135</p>