-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
  • 29,919
  • 31
  • 129
  • 183
Mike Boutin
  • 5,178
  • 11
  • 35
  • 63

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,301
  • 1
  • 11
  • 31