passport js missing credentials

前端 未结 7 833
夕颜
夕颜 2020-12-31 02:03

Been working on this for a few hours now, pretty frustrating...

router.post(\'/\',
passport.authenticate(\'local-signup\', function(err, user, info) {
    co         


        
7条回答
  •  猫巷女王i
    2020-12-31 02:45

    I see your req.body contains {password: 'password', email: 'email@email.com'}. email is not what passportjs is looking for, but username is. You can either change your input names on your HTML/JS, or you can change the default parameters passportjs is looking for in req.body. You need to apply these changes where you define your strategy.

    passport.use(new LocalStrategy({ // or whatever you want to use
        usernameField: 'email',    // define the parameter in req.body that passport can use as username and password
        passwordField: 'password'
      },
      function(username, password, done) { // depending on your strategy, you might not need this function ...
        // ...
      }
    ));
    

提交回复
热议问题