Node.js + express.js + passport.js : stay authenticated between server restart

后端 未结 7 655
谎友^
谎友^ 2020-12-04 05:12

I use passport.js to handle auth on my nodejs + express.js application. I setup a LocalStrategy to take users from mongodb

My problems is that users have to

7条回答
  •  Happy的楠姐
    2020-12-04 05:51

    This is probably obvious to experienced node users but it caught me out:

    You need to configure the node session - e.g.

    app.use(session({secret: "this_is_secret", store: ...}));
    

    before initializing the passport session - e.g.

    app.use(passport.initialize());
    app.use(passport.session());
    

    If you call passport.session() first it won't work (and it won't warn you). I thought the problem was with the serialize/deserialize user functions and wasted hours.

提交回复
热议问题