Cluster with Passport NodeJs

北战南征 提交于 2019-12-24 18:06:25

问题


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?



来源:https://stackoverflow.com/questions/50317815/cluster-with-passport-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!