Hey, still trying to figure out how to do the user authentication on my app.
I have an example from a tutorial that uses express-session and passportjs. In that example, there is a middleware like this:
app.use(function (req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
});
From what I understand, it creates some local variables that will be available to the front-end. In the templates, I can use {{user}} to show the user object.
For some reason, I canât get it to work in my React project. I try doing this:
if(user){
console.log(user)
}
and my code wonât even compile because âuserâ is not defined.
am I misunderstanding how res.locals works?
Or is it just React being fussy? I really donât understand what the problem is⌠if âuserâ was undefined, it should just not run the console.log and move on, right?