Passport.js: how to access user object after authentication?

后端 未结 7 1252
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 14:01

I\'m using Passport.js to login a user with username and password. I\'m essentially using the sample code from the Passport site. Here are the relevant parts (I think) of my c

7条回答
  •  北海茫月
    2021-02-01 14:44

    You'll need to make sure that you register a middleware that populates req.session before registering the passport middlewares.

    For example the following uses express cookieSession middleware

    app.configure(function() {
    
      // some code ...
    
      app.use(express.cookieParser());
      app.use(express.bodyParser());
      app.use(express.cookieSession()); // Express cookie session middleware 
      app.use(passport.initialize());   // passport initialize middleware
      app.use(passport.session());      // passport session middleware 
    
      // more code ...
    
    });
    

提交回复
热议问题