我无法使用passort.js和express.js进行注册和login,在本地这工作得很好,但是当我在远程服务器上部署应用程序时,login后login无法redirect。 它甚至不会刷新失败消息。

我还注意到,当我在远程服务器上注册时,它工作正常,但不闪烁的消息。 req.isAuthenticated()总是返回false。 我正在使用MongoDB作为我的数据源

app.use(session({secret : '3T67774A-R649-4D44-9735-43E296ZZ980F', saveUninitialized: true, resave: true})); app.use(passport.initialize()); app.use(passport.session()); // persistent login sessions app.use(flash()); // use connect-flash for flash messages stored in session function isLoggedIn(req, res, next) { console.log("Request Authenticated: " + req.isAuthenticated()); if (req.isAuthenticated()) return next(); res.redirect('/login'); } passport.use('local-login', new LocalStrategy({ // by default, local strategy uses username and password, we will override with email usernameField : 'email', passwordField : 'password', passReqToCallback : true // allows us to pass in the req from our router (lets us check that a use is logged in or not }, function(req, email, password, done) { if (email) email.toLowerCase(); // use lower-case emails to avoid case-sensitive email matching // asynchronous process.nextTick(function() { User.findOne({'' : email}, function(err, user) { // if there are any errors, return the error if (err) return done(err); // if no user found, return the message if (!user) return done(null, false, req.flash('loginMessage', 'User not found.')); if (!user.isValidPassword(password)) return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.')); // return user else return done(null, user); }); }); })); 


网上收集的解决方案 "nodejs会话在本地工作,但不在远程服务器上"