Last active
April 24, 2020 18:12
-
-
Save piyushgarg-dev/da7dde75e42cbe106910cfe123c0a18b to your computer and use it in GitHub Desktop.
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
| 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 = { | |
| } | |
| 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