In our application, we use a Passport middleware (localStrategy, sessions are stored in a MongoStore). We decided to use Clusters in order to speed up and ease on a server. The problem is that after this change, passport always is in "not authorized" state. Is it possible to use passport (localStrategy) with clustering?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Passport store session data in memory. With Clustering, It is possible for passport to store data in a cluster and other requests handle by other clusters. You must use a session store. I recommend using connect-redis
Also these links are helpful:
1-https://blog.risingstack.com/node-hero-node-js-authentication-passport-js/
2-Using passport and OAuth with connect-redis
3-https://afshinm.name/2014/06/26/using-redis-as-session-store-for-expressjs-passportjs-settings/
4-https://www.airpair.com/express/posts/expressjs-and-passportjs-sessions-deep-dive
Update
For MongoDb read these links
1-Can't store session in MongoDB with passport
2-How can I manage sessions with Passport JS for some routes using express?