I am using nodejs with express 4 framework. I have setup my node project on server but the problem is that after the login it will not redirect me to dashboard page. When i check "req.user" after login then it gave me undefined value although its working fine in my local system.
But when i point the ip with domain name then session is initializing successfully. and it redirect me to dashboard page and also gave me req.user information.
This is my session code.
var sessionStore = new SessionStore({}, connection);
// required for passport
app.use(session({
secret: '5372E653ED6BD22E09BF14DE621CAFBFEA8B1391C056B73F3A0FECB31BD4E1B8',
cookie: { maxAge : 2592000000 },
store: sessionStore,
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(routes);
Route code (after login)
router.all('/user/*', function (req, res, next) {
if (!req.user) {
res.redirect("/login.html");
} else {
next();
}
});
Any Idea?
I think it is intentionally happening in the browser. This doesn't sound like an express issue.
Related issues here:
IP and domain create different session
Why does the session cookie work when serving from a domain but not when using an IP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.