I'm wondering if there is a way to put user data available in session, in response of routes by default. For example writing something like this:
app.get("/someRandomPath",PutUserData,function(req,res,next)
{
res.render("myView",{title:"my page title"})
}
function PutUserData(req,res,next)
{
if(auth)
{
res.send({user:session.user}
next()
}
else next()
}
or even better do something in application level such as app.use(...)
?
The reason I want to do this is I want to avoid checking if user is Authed or not in every single route and render views with different data.
I'd appreciate your help.