Last active
August 29, 2015 14:00
-
-
Save edefiez/11408379 to your computer and use it in GitHub Desktop.
Passportjs protect site if user not logged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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