Skip to content

Instantly share code, notes, and snippets.

@BenHall
Created February 29, 2012 14:48
Show Gist options
  • Save BenHall/1941301 to your computer and use it in GitHub Desktop.
Save BenHall/1941301 to your computer and use it in GitHub Desktop.
passport.js auth route
exports.ensureAuthenicated = function(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/login')
}
var passport = require('./auth/passport');
app.get('/', passport.ensureAuthenicated, function(req, res){
res.redirect('/acquisition');
});
@drusellers
Copy link

Ok, cool. So I have to stuff that ensureAuthenticated in each time? Thanks Ben!

@BenHall
Copy link
Author

BenHall commented Feb 29, 2012

Yep, any routes which require the user to be logged in need to have that in the pipeline.

@drusellers
Copy link

thanks ! worked like a champ.

@DeviaVir
Copy link

Just a small typo:
ensureAuthenicated
which should be
ensureAuthenticated

Had me thrown off for a bit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment