Created
May 30, 2018 22:53
-
-
Save AntonioErdeljac/3baa23e152bbc068eebd730e05918eca to your computer and use it in GitHub Desktop.
This file contains 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 mongoose = require('mongoose'); | |
const passport = require('passport'); | |
const LocalStrategy = require('passport-local'); | |
const Users = mongoose.model('Users'); | |
passport.use(new LocalStrategy({ | |
usernameField: 'user[email]', | |
passwordField: 'user[password]', | |
}, (email, password, done) => { | |
Users.findOne({ email }) | |
.then((user) => { | |
if(!user || !user.validatePassword(password)) { | |
return done(null, false, { errors: { 'email or password': 'is invalid' } }); | |
} | |
return done(null, user); | |
}).catch(done); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment