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

后端 未结 7 1383
佛祖请我去吃肉
佛祖请我去吃肉 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:27

    late to party but this worked for me

    use this in your app.js

    app.use(function(req,res,next){
      res.locals.currentUser = req.user;
      next();
    })
    

    get current user details in client side like ejs

    <%= locals.currentUser.[parameter like name || email] %>
    

提交回复
热议问题