Skip to content

Instantly share code, notes, and snippets.

@Qaaj
Last active February 25, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qaaj/2ef39c23673c15aedb3d to your computer and use it in GitHub Desktop.
Save Qaaj/2ef39c23673c15aedb3d to your computer and use it in GitHub Desktop.
// User requests the /app/ route -> Check if he is authenticated
router.get('/app/', isAuthenticated, (req, res) => res.render('app') );
// The isAuthenticated function is using passport.js here to see if the user is logged in (req.isAuthenticated)
// It that's not the case, we redirect them to the login route.
const isAuthenticated = (req, res, next) => {
if(req.isAuthenticated()) return next();
res.redirect('/login');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment