Home > front end >  Made the back-end nodejs, page data in a session after the jump disappear, how can I solve?
Made the back-end nodejs, page data in a session after the jump disappear, how can I solve?

Time:09-25

My front page on ngnix inside, port is 80

My background is written in nodejs, port is 3060,

Requests for log in, now I'm on the landing page http://www.xinlizhiyouni.com:80/test/user/login interface, and then save the data to nodejs session, then jumps to http://www.xinlizhiyouni.com:80/test/user/logout http://www.xinlizhiyouni.com:80/advertise/add.html request interface, this session data for undefined, however, could you tell me why I lost the session data and how to keep data in the session, right after and then jump not lose

 
Let identityKey='superKey';

App. Use (cookieParser ());
App. Use (session ({
Name: identityKey,
Secret: 'heart',//to the session id cookie related to sign
Cookie: {maxAge: 60000},
Resave: false
}));

//set the cross-domain access
App. All (' * ', function (the req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
Res. The header (" Access - Control - Allow - Headers ", "X - Requested - With");
Res. The header (" Access - Control - Allow - the Methods ", "PUT, POST, GET, DELETE, the OPTIONS");
Res. The header (" X - Powered By ", '3.2.1);
Res. The header (" the content-type ", "application/json; charset=utf-8");
next();
});

App. All ('/', function (the req, res, next) {
Let sess=the req. Session;
Let loginUser=sess. LoginUser;
Let isLogined=!!!!! LoginUser.
});

//login interface
App. All ('/test/user/login ', function (the req, res, next) {
Let sess=the req. Session;
Let the user={
"Name" : the req. Body. The name
};
The console. The log (" landing interface test ");
Sess. LoginUser=user. The name;
Res. SetHeader (" Set - the cookies, "[" sid=1; path=/domain=w; expires=" + new Date (" 2030 ") ");
Res. Json ({ret_code: 0, ret_msg: 'login successful});
});

App. All ('/test/user/logout ', function (the req, res, next) {
Let sess=the req. Session;
Let loginUser=sess. LoginUser;

The console. The log (" logout interface test ");
The console. The log (loginUser);

});

CodePudding user response:

The building Lord, please solve the problem? I also am such problems, a routing under session, another route to take out the session is undefined, the original poster is how to solve?

CodePudding user response:

Session can be saved to the localStorage, or in the database

CodePudding user response:

You put your expiration time setting, long is too short,
  • Related