Nodejs Passport display username

后端 未结 5 1528
感情败类
感情败类 2020-12-08 05:16

In nodeJS I am using the passport module for authentication. I would like to show the username of the currently logged in user.

I tried the following code:



        
5条回答
  •  感情败类
    2020-12-08 05:30

    Helpers are not supported with Express v4.x

    A good alternative is to create a middleware such as:

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

    Then you can use the "user" variable in your views.

提交回复
热议问题