Skip to content

Instantly share code, notes, and snippets.

@edefiez
Last active August 29, 2015 14:00
Show Gist options
  • Save edefiez/11408379 to your computer and use it in GitHub Desktop.
Save edefiez/11408379 to your computer and use it in GitHub Desktop.
Passportjs protect site if user not logged
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/login')
}
app.all('*', function(req,res,next){
if (req.params === '/' || req.params === '/login')
next();
else
ensureAuthenticated(req,res,next);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment