Authentication failed on failed request: Missing credentials

I am working on the login page for Passport NodeJs, Express. I am a web developer, but this is my first NodeJS project.

I follow this guide: http://mherman.org/blog/2013/11/11/user-authentication-with-passport-dot-js/

But every time I try to enter the login page or the registration page, the only thing I have is the Bad Request page.

I called back to find out what happened:

exports.postRegister = function(req, res){                                
  login = mongoose.model('login'); 
  login.register(new login ({ username : req.body.email}),req.body.password, function(err, login){
      if (err){
         return res.render('register', { login: login, error: err, title: "S'enregistrer" }); 
      }   
      // Something is wrong here 
      passport.authenticate('local', function(err, user){
          // So let console log the thing !
          console.log(arguments);
      })(req, res, function(){
          res.redirect('/scene/1');
      }); 
  }); 
};

And the .log (arguments) console returns:

{ '0': null,
  '1': false,
  '2': { message: 'Missing credentials' },
  '3': 400 }

I have a check on my MongoDB, the user is created without problems!

+4
source share
2 answers

, login. :

var Model = mongoose.model('Model', 'modelSchema');

+1

, POSTMAN , curl :

curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"username": "test", "password": "test"}' http://localhost:3000/api/login
+1

Source: https://habr.com/ru/post/1533952/