import passport from 'passport';
import passportLocal from 'passport-local';
import user from '../models';

const LocalStrategy = passportLocal.Strategy;

passport.serializeUser((user, done) => {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, (err, user) => {
    done(err, user);
  });
});


passport.use(new LocalStrategy({ passReqToCallback: true }, (req, username, password, done) => {
  user.User.findOne({
    where: {
      username
    }
  }).then((users, err) => {
    if (!users) {
      return done(null, false, { message: 'Incorrect username' });
    }
    if (users.password !== req.body.password) {
      return done(null, false, { message: ' Incorrect password.' });
    }
    return done(null, users);
  }).catch(err => done(err));
}
));

module.exports = passport;


import passport from 'passport';
import passportLocal from 'passport-local';
import user from '../models';

const LocalStrategy = passportLocal.Strategy;

passport.serializeUser((sessionUser, done) => {
  done(null, sessionUser.id);
});

passport.deserializeUser((id, done) => {
  User.findById(id, (err, sessionUser) => done(err, sessionUser));
});


passport.use(new LocalStrategy({ passReqToCallback: true }, (req, username, password, done) => {
  user.User.findOne({
    where: {
      username
    }
  }).then((users, err) => {
    if (!users) {
      return done(null, false, { message: 'Incorrect username' });
    }
    if (users.password !== req.body.password) {
      return done(null, false, { message: ' Incorrect password.' });
    }
    return done(null, users);
  }).catch(err => done(err));
}
));

module.exports = passport;


Refactor code using es6 syntax
Refactor code using es6 syntax
