text: const passport = require('passport');
  const LocalStrategy = require('passport-local').Strategy;
  const JwtStrategy = require('passport-jwt').Strategy;
  const User = require('./models/User');
  
  const cookieExtractor = req =>{
      let token = null;
      if(req && req.cookies){
          token = req.cookies["access_token"];
      }
      return token;
  }
  
  // authorization 
  passport.use(new JwtStrategy({
      jwtFromRequest : cookieExtractor,
      secretOrKey : process.env.JWT_SECRET
  },(payload,done)=>{
      User.findById({_id : payload.sub},(err,user)=>{
          if(err)
              return done(err,false);
          if(user)
              return done(null,user);
          else
              return done(null,false);
      });
  }));
  
  passport.use('login', new LocalStrategy({
      usernameField : 'email',
      passwordField : 'password'
    }, async (email, password, done) => {
      try {
        const user = await User.findOne({ email });
        if( !user ){
          return done(null, false, { message : 'User not found'});
        }
        const validate = await user.isValidPassword(password);
        if( !validate ){
          return done(null, false, { message : 'Wrong Password'});
        }
        return done(null, user, { message : 'Logged in Successfully'});
      } catch (error) {
        return done(error);
      }
    }));
  