Skip to content

Instantly share code, notes, and snippets.

@thihenos
Last active July 13, 2018 19:21
Show Gist options
  • Save thihenos/91b8b4e4e234e203feba753772122179 to your computer and use it in GitHub Desktop.
Save thihenos/91b8b4e4e234e203feba753772122179 to your computer and use it in GitHub Desktop.
exports.IsAuthenticated = function(req,res,next){
//Passport creates a function to your session called isAuthenticated(), so you can use it to verify if the user really login in the app
console.log(req.isAuthenticated());
if(req.isAuthenticated()){
//So, here you are saying that if the route called had any other function, it will goes to the next one ( which is rendering the HTML )
next();
}else{
//Or else, goes back to login page
res.render('welcome/index',{message:'Ops! This route requires a login!'});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment