我已经阅读了这个主题Node.js + express.js + passport.js :在服务器重新启动之间保持身份验证,我需要完全相同的东西,但对于 Redis。我使用了这样的代码:
var RedisStore = require('connect-redis')(express);
app.use(express.session({
secret: "my secret",
store: new RedisStore,
cookie: { secure: true, maxAge:86400000 }
}));
它不起作用。要连接 Redis,我使用 connect-redis 模块。我做错了什么?谢谢!
UPD:我没有收到任何错误。为了确保身份验证过程成功,我添加了日志行,它会执行。
function(email, password, done) {
// asynchronous verification, for effect...
process.nextTick(function() {
findByEmail(email, function(err, user) {
if (!user) {
return done(null, false, {
message: 'Unknown user ' + email
});
}
if (user.password != password) {
return done(null, false, {
message: 'Invalid password'
});
}
//just logging that eveything seems fine
console.log("STATUS: User " + email + " authentificated succesfully");
return done(null, user);
})
});
}));
启用 express.logger() 的日志是:
127.0.0.1 - - [Fri, 19 Oct 2012 05:49:09 GMT] "GET /ico/favicon.ico HTTP/1.1" 404 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4"
STATUS: User admin authentificated succesfully
我确实认为 auth/users/credentials/serializing/deserializing 本身没有任何问题。问题只是护照无法将cookie设置为Redis并读取它。