What is your hint or solution suggestion?
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/');
};
!!!MAKE SURE, THAT YOUR CODE HAS title: ‘Home page’ IN res.render!!!
app.route("/").get((req, res) => {
//Change the response to render the Pug template
res.render(process.cwd() + '/views/pug/index', {title: 'Home page', message: 'Please login', showLogin: true});
});
app.route("/login").post(passport.authenticate('local', { failureRedirect: '/' }), (req, res) => {
res.redirect("/profile");
});
app.route('/profile').get(ensureAuthenticated, (req,res) => {
res.render(process.cwd() + '/views/pug/profile');
});
Challenge: Create New Middleware
Link to the challenge: