text: const LocalStrategy = require('passport-local').Strategy;
  const mongoose = require('mongoose');
  const bcrypt = require('bcryptjs');
  
  //load user model
  const User = require('../models/Admin');
  
  module.exports = function(passport) {
      passport.use(
          new LocalStrategy({usernameField: 'inputEmail' }, (inputEmail, password, done) => {
              // match user
              User.findOne({inputEmail: inputEmail})
              .then(user => {
                  if(!user) {
                    return done(null, false, {message: 'The User Name is not registered'});  
                  }
                  //match password
                  bcrypt.compare(password, user.password, (err, isMatch) => {
                      if(err) throw err;
  
                      if(isMatch){
                          return done(null, user);
                      }else{
                          return done(null, false, {message: 'Password incorrect'});
                      }
  
                  })
              })
              .catch(err => console.log(err));
          })
      );
  
      passport.serializeUser(function(user, done){
          done(null, user.id);
      });
  
      passport.deserializeUser (function(id, done){
          User.findById (id, function(err, user){
              done(err, user);
          });
      });
  }