首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我要实现序列化和反序列化NodesJS + Passport + RedisStore吗?

我要实现序列化和反序列化NodesJS + Passport + RedisStore吗?
EN

Stack Overflow用户
提问于 2013-10-09 17:59:03
回答 1查看 21.9K关注 0票数 19

我实现序列化和反序列化了吗?

使用Express将RedisStore设置为我的会话存储。这是否意味着我没有实现序列化和反序列化?它会自动发生吗?

当我没有实现这些方法时,我得到下面的Express error - 500错误:无法将用户序列化到会话中。当我实现它们时,我不确定要在反序列化中放入什么。

下面的代码似乎可以工作,但会话不是持久的。我每次访问该网站时都需要登录。

有没有NodeJS + Passport + RedisStore的好例子?

var sessionStore = new RedisStore({
                                        host: rtg.hostname,
                                        port: rtg.port,
                                        db: redisAuth[0],
                                        pass: redisAuth[1]
                                      });

passport.use(new ForceDotComStrategy({
    clientID: clientId,
    clientSecret: clientSecret,
    callbackURL: myurl
},
function(token, tokenSecret, profile, done) {
    console.log(profile);
    return done(null, profile);
  }
));

appSecure.configure('production', function(){
appSecure.use(allowCrossDomain);
appSecure.use(express.cookieParser(expressSecret));
appSecure.use(express.bodyParser());
appSecure.use(express.methodOverride());
appSecure.set('port', port); 
appSecure.use(express.session({ secret: expressSecret, store: sessionStore, key:'expressSid', cookie: { maxAge : 604800, domain:'.domain.com'}})); 
appSecure.use(passport.initialize());
appSecure.use(passport.session());
appSecure.use(appSecure.router);
appSecure.use(express.static(__dirname + '/public'));
appSecure.use(express.errorHandler());
});

passport.serializeUser(function( user, done ) {
    done( null, user.id);
});

passport.deserializeUser(function( user, done ) {
    done( null, user );
});
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19268812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档