Express-session middleware session can not get the problem

I have two requests, an and b. When I set up session, through an and then visit B, what is the undefined, request?

const express     = require("express");
const app = express();
const session     = require("express-session");

app.use(session({
  secret:  "key", // session id cookie 
  resave: false,
  saveUninitialized: true, // 
  cookie: {
   maxAge: 100000, //  session 
   secure: true
  },
}));

app.post("/a",function(req, res) {
  req.session.name = "Thomas";
});

app.post("/b", function(req, res) {
   console.log(req.session.name) //undefined
});
< hr >

big head, help you edit

Mar.21,2021

Brother is currently having a headache


the server thinks that your request is initiated by two different clients, so the second request is undefined


I also encounter this situation. Just remove maxAge: 100000

.
Menu