Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Last active April 24, 2020 18:12
Show Gist options
  • Select an option

  • Save piyushgarg-dev/da7dde75e42cbe106910cfe123c0a18b to your computer and use it in GitHub Desktop.

Select an option

Save piyushgarg-dev/da7dde75e42cbe106910cfe123c0a18b to your computer and use it in GitHub Desktop.
const LocalStrategy = require('passport-local').Strategy;
module.exports = function(passport){
passport.use(
new LocalStrategy({usernameField: 'email'}, (email, password, done) => {
// ... do the database stuff with email and passsword and get all the details
// of user. In this case I am hardcoding the user.
const user = {
email
}
if(user){
done(null, user);
}
else{
done(null, false, {message: "Incorrect username"});
}
})
)
passport.serializeUser(function(user, done) {
done(null, user.email);
});
passport.deserializeUser((email, done) => {
// Find user by the email from your db
const user = {
email,
name: 'Piyush', // In future, this value would come from your db
}
done(null, user)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment