我已经阅读了Node.js + express.js + passport.js : stay authenticated between server restart这个主题,我需要完全相同的内容,但对于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/deserialize本身没有错。问题在于 Passport 无法将cookie设置为Redis并读取它。

最佳答案

我应该用

cookie: { secure: false, maxAge:86400000 }

关于node.js - Nodejs + Passport.js + Redis : how to store sessions in Redis,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12947965/

10-12 13:35
查看更多