Authentification fail in bad request : Missing Credentials

I'm working on a Passport Node.js, Express login page. I'm a Web Developer but this is my first Node.js project.

I have followed User Authentication with Passport.js

But every time I try to log in the login page, or the Register page, the only thing I have is a "Bad request" page.

I made a call back to see what happened:

exports.postRegister = function(req, res) {
    login = mongoose.model('login');
    login.register(new login({
    }), 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's console log the thing !
        })(req, res, function() {

And the console.log (arguments) return:

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

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


It looks like you're not specifying a schema for your login model. You need to declare models like this:

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

If you want to see whether it comes from POSTMAN or your code, you can test with curl in a terminal:

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

Need Your Help

How can I stop Eclipse warning about target folder's contents?

java eclipse warnings

I'm getting loads of warnings from generated files in my target folder (e.g. Java code generated from XSDs or surefire reports) that I can't fix, and it's hiding proper warnings in my source code.

Host-Only Network not working on VMware Workstation

linux windows-8 vmware-workstation

I installed WMware Workstation 9.0.2 on Windows 8 pro x64. I created an Oracle linux 6.4 virtual machine. I'm connecting to internet using only wireless on windows and my gateway is ( ...