Skip to content

Instantly share code, notes, and snippets.

@thihenos
Created July 7, 2018 15:54
Show Gist options
  • Save thihenos/a3db47d5c7e982ed25065154c822772f to your computer and use it in GitHub Desktop.
Save thihenos/a3db47d5c7e982ed25065154c822772f to your computer and use it in GitHub Desktop.
// Using Passport for local strategy
passport.use('local-login', new LocalStrategy ({
//In this part, passport will use' the input in HTML, by using it's name for the strategy
usernameField : 'login',
passwordField : 'password'
,passReqToCallback : true},function (req,login,password,done){
//Querying on database to find the user by the email or the login
db.User.find({ where: { username: req.body.login }}).then(function(result) {
//Verify if the query returns a result
if(result){
console.log('Login OK');
//finishing the by sereliazing user object attributes
done(null,result);
} else {
console.log('Login ou senha errado');
done(null,false,{message : 'Username or password are wrong :('});
}
});
}//Fim função de procura do usuario
));//Fim passport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment