问题描述
我想使用cookie会话存储与Passport,因为内存商店不是为生产设计:
I want to use cookie session store with Passport because memory store is not designed for production:
Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
这是我的Express初始化:
Here's my Express initialization:
app.use(express.bodyParser({keepExtensions:true}));
app.use(express.cookieParser(cookieSecret));
app.use(express.cookieSession({
key: cookieKey,
secret: cookieSecret,
maxAge: sessionTimeout
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
如果我更改 express.cookieSession
到 express.session
。当使用 cookieSession
时,用户登录成功,但用户在下一页加载后不再登录。
Everything works normally if I change express.cookieSession
to express.session
. When using cookieSession
user login succeeds but the user is not logged in anymore after next page load occurs. Any tips how to make passport work with cookie sessions?
我使用Express 3.0.0
I'm using Express 3.0.0
推荐答案
我知道这是老,但我有同样的问题。原来你不需要(实际上你不能)在cookieParser和cookieSession中设置秘密
选项。
I know this is old, but I had the same issue. Turns out you don't need to (in fact you can't) set the secret
option in both cookieParser and cookieSession.
查看我对我自己的帖子的回答:
See my answer on my own post: http://stackoverflow.com/a/30109922/3500059
这篇关于使用cookieSession与Passport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!