Problems that cannot be obtained by express.session

here"s the thing. I want to make a landing page. First of all, A.html is a login page, and login is a post request. After a successful login, the server writes the login name of the req.session.LoginName=" user. "the front end jumps to the B page, and the B page first initiates a get request, and then the server checks whether req.session.LoginName returns req.session.LoginName, but the actual output is that req.session is always undefined.

.

Core Code:
[app.js]

var express = require("express");
var app = express();
var router = require("./router/router.js");
var session = require("express-session");

app.use(session({
     secret: "keyboard cat",
     //name: "connect.sid",   //namecookienamecookiename:connect.sid
     cookie: {maxAge: 80000 },  //maxAge80000ms80ssessioncookie
     resave: false,
     saveUninitialized: true
  }));

//
app.post("/doLogin",router.doLogin);
app.get("/checkloginBysession",router.checkloginBysession);

[router.js]

exports.doLogin = function (req, res, next){
    //...  
     req.session.LoginName=username.toString();
     console.log(""+req.session.LoginName);//
     res.end("{"state":"1","msg":""}");
}
exports.checkloginBysession =function(req, res, next) {
    //req.session.LoginName=username.toString();
    res.writeHead(200,{"Content-type":"application/json;charset=UTF8","Access-Control-Allow-Origin":"*"});
    console.log(""+req.session.LoginName);//undefined
    if (req.session.LoginName) {
        res.end("{"state":"1","msg":"session"}");
        return;
    }
    else
    {
        res.end("{"state":"0","msg":""}");
        return;
    }
}

Thank you in advance ~

Dec.29,2021

I have the same problem. I use the express5.0.0 framework 4. I can write like this.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b0af-2c254.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b0af-2c254.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?