2
我一直在本地與Couch和Redis一起構建Express應用程序。它一直在正常工作。使用Express'Connect-Redis將會話存儲在遠程Redis服務器上
我現在試圖使用託管在Iris Redis上的遠程Redis服務器。我已經嘗試了幾天,但似乎無法使用Passport的本地策略進行身份驗證後,Express'Connect-redis返回cookie。但是,當我運行本地Redis服務器時,這樣工作得很好。
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use('/upload', upload.fileHandler());
app.use(express.bodyParser({ keepExtensions: true, uploadDir: 'public/uploads' }));
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ cookie: { maxAge: 60000000 }, secret: "sauce", store: new RedisStore({
port: 6379,
host: 'url',
pass: 'sauce'
}) }));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
// Authentication
passport.use(new LocalStrategy(function(username, password, done) {
username = username.toLowerCase();
db.get(username, function (err, doc) {
if (err) {
console.log(err);
return done(err);
}
if (!doc) {
return done(null, false, { message: 'No user by that name.' });
}
if (doc.password !== password) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, doc);
});
})
);
passport.serializeUser(function (user, done) {
done(null, user._id);
});
passport.deserializeUser(function (userId, done) {
db.get(userId, function(err, user){
if(err){
return (500, err);
} else {
done(null, _.omit(user, ["password"]));
}
});
});
// Route
exports.authenticate = passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login'
});