What does passport.session() middleware do?

前端 未结 4 1698
小鲜肉
小鲜肉 2020-12-04 05:58

I am building an authentication system using Passport.js using Easy Node Authentication: Setup and Local tutorial.

I am confused about what passport.session()<

4条回答
  •  醉酒成梦
    2020-12-04 06:05

    While you will be using PassportJs for validating the user as part of your login URL, you still need some mechanism to store this user information in the session and retrieve it with every subsequent request (i.e. serialize/deserialize the user).

    So in effect, you are authenticating the user with every request, even though this authentication needn't look up a database or oauth as in the login response. So passport will treat session authentication also as yet another authentication strategy.

    And to use this strategy - which is named session, just use a simple shortcut - app.use(passport.session()). Also note that this particular strategy will want you to implement serialize and deserialize functions for obvious reasons.

提交回复
热议问题