Passport: Unknown authentication strategy “local”

前端 未结 3 434
别那么骄傲
别那么骄傲 2021-02-04 02:52

I\'m new to NodeJS and I try to build a login/registration system. Registration works fine but I\'m currently unable to login.

I find a example app using passport and no

3条回答
  •  滥情空心
    2021-02-04 03:48

    i have done like this and it worked

    $npm install passport-local

    var passport = require('passport');
    var LocalStrategy = require('passport-local').Strategy; /* this should be after passport*/
    
    
    
     passport.use(new LocalStrategy(
      function(username, password, done) {
        User.findOne({ username: username }, function(err, user) {
          if (err) { return done(err); }
          if (!user) {
            return done(null, false, { message: 'Incorrect username.' });
          }
          if (!user.validPassword(password)) {
            return done(null, false, { message: 'Incorrect password.' });
          }
          return done(null, user);
        });
      }
    ));
    

提交回复
热议问题