Show user all frontend views with res.locals

Hello guys,

I am trying to develop in nodejs and express an admin panel.

I am using passport with the LocalStrategy for authentication.

I would like to show theuser.name in all the frontends in the navigation bar. Hence, passing the user all the time by the routes to the frontend is not an option. For this I have written the following custom middleware:


app.use(passport.initialize())
app.use(passport.session())
app.use((req, res, next) => {
  res.locals.user = req.user
  console.log(req.user)
  console.log(res.locals.user)
  next()
})

However, both console.log request give me undefined back.

Please find here my github repo for the full minimum viable example.

Any suggestions why the user is not displayed properly in my frontend?

As I am trying to fix this error for several days now, I am looking forward to your replies!