0
votes

I'm building a node + express app, and i need to pass the login data in every route, like this:

app.get('/dashboard', isLoggedIn, (req, res) => {
        res.render('dashboard/dashboard', { user: req.user });
});

There's a way to always pass req.user as user to the view? (I'm using EJS btw)

I already have a middleware to check if the user is logged, or he will be redirected to login.

Thanks!

1

1 Answers

2
votes

You can use app.use method

app.use(isLoggedIn);

Then:

app.get('/dashboard', (req, res) => {
    res.render('dashboard/dashboard', { user: req.user });
});