0

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 Answer 1

2

You can use app.use method

app.use(isLoggedIn);

Then:

app.get('/dashboard', (req, res) => {
    res.render('dashboard/dashboard', { user: req.user });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.