passport js missing credentials

前端 未结 7 677
夕颜
夕颜 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条回答
  • 2020-12-31 02:24

    In Router.post:

    router.post('/', passport.authenticate('local-signup', {
        successRedirect: '/dashboad',
        failureRedirect: '/',
        badRequestMessage: 'Your message you want to change.', //missing credentials
        failureFlash: true
    }, function(req, res, next) {
    ...
    
    0 讨论(0)
  • 2020-12-31 02:25

    In my case add all the field inside of config works:

    passport.use(new LocalStrategy({
      usernameField : 'email',
      passwordField : 'password',
      passReqToCallback : true
    }))
    
    0 讨论(0)
  • 2020-12-31 02:32

    if you are using passport local mongoose as a plugin with your user model.

    Try this:

    passport.use(new LocalStrategy({
      usernameField: 'email'
    }, User.authenticate()));
    
    0 讨论(0)
  • 2020-12-31 02:42

    Mine was spelling mistake issue. I hade usernameFeild: 'email',

    However, it should be usernameField: 'email',

    0 讨论(0)
  • 2020-12-31 02:42

    There could be a mistake in field-type that's why passport.js is not able to recognize the correct field and gives error .

    CORRECTION: check in .ejs file if your username and password fields correctly state type. type="password" id="password" name="password"//CORRECTLY SPECIFIED.

    What you might have done is : Type:"text" in ejs file and told passport to look for type:"password"

    Tip : Check for spelling mistakes in type fields. eg: type:password in ejs & type:Password

    0 讨论(0)
  • 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 ...
        // ...
      }
    ));
    
    0 讨论(0)
提交回复
热议问题