Sending back a JSON response when failing Passport.js authentication
I'm using Node.js as a backend API server for an iPhone client. I'm using Passport.js to authenticate with a local strategy . The relevant code is below: // This is in user.js, my user model UserSchema.static('authenticate', function(username, password, callback) { this.findOne({ username: username }, function(err, user) { if (err){ console.log('findOne error occurred'); return callback(err); } if (!user){ return callback(null, false); } user.verifyPassword(password, function(err, passwordCorrect){ if (err){ console.log('verifyPassword error occurred'); return callback(err); } if (