-1

I try to put my req.user value in the global variable for all views with

app.use(function(req, res, next){
    res.locals.user = req.user; // this line
    res.locals.success = req.flash('success');
    res.locals.error = req.flash('error');
    next();
});

but nothing works. I have to put it on every render() function. What did I do wrong?

Thank you for your help!

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
Mike Boutin
  • 5,297
  • 12
  • 38
  • 65

1 Answers1

0

I'm not sure but I don't think you are using the req.flash correctly resulting in it returning undefined.

You should probably give it a second value.

Take a look at this post and see if you can figure it out: How to send flash messages in Express 4.0?

Community
  • 1
  • 1
Victor Axelsson
  • 1,420
  • 1
  • 15
  • 32