May 2018
Intermediate to advanced
492 pages
12h 3m
English
The changes required here are more significant, but still straightforward:
import { ensureAuthenticated } from './users';
We need to use the ensureAuthenticated function to protect certain routes from being used by users who are not logged in. Notice how ES6 modules let us import just the function(s) we require. Since that function is in the user router module, we need to import it from there:
router.get('/add', ensureAuthenticated, (req, res, next) => { try { res.render('noteedit', { title: "Add a Note", docreate: true, notekey: "", user: req.user, note: undefined }); } catch (e) { next(e); }});
The first thing we added is to call usersRouter.ensureAuthenticated in the route definition. ...
Read now
Unlock full access