Browse Source

🔨 Change passport email field to username

main
Haris Razis 4 years ago
parent
commit
fd02551c1b
  1. 11
      server/services/passport.js

11
server/services/passport.js

@ -16,12 +16,15 @@ passport.deserializeUser(function (id, done) {
}); });
passport.use('local', new LocalStrategy( passport.use('local', new LocalStrategy(
{usernameField: 'email'}, {
(email, password, done) => { usernameField: 'username',
User.findOne({email: email}) passwordField: 'password'
},
(username, password, done) => {
User.findOne({username: username})
.then(user => { .then(user => {
if (!user) { if (!user) {
const newUser = new User({email, password}); const newUser = new User({username, password});
bcrypt.genSalt(10, (err, salt) => { bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => { bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err; if (err) throw err;

Loading…
Cancel
Save