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

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

    res.render accepts an optional parameter that is an object containing local variables for the view.

    If you use passport and already authenticated the user then req.user contains the authenticated user.

    // app.js
    app.get('/dashboard', (req, res) => {
      res.render('./dashboard', { user: req.user })
    })
    

    // index.ejs
    <%= user.name %>
    

提交回复
热议问题