Trying to login using the data I've created which are in the db however when I post the user&pass back to call /api/login endpoint the network response for this endpoint is stuck on pending request. Check the response and it showing the payload data I'm trying to send back to mongo.
I tried putting $q defer promise in vm.loginuser controller where the call is happening but no avail. Even postman can't do a login process its also stuck on pending request.
Angular Ctrl:
vm.loginUser = function () {
$http.post('/api/login', vm.userlogin).success(function(response){
console.log('redirect to profile');
}).error(function(error){
console.log('err');
});
};
also if I use .then
instead of .success
I get an error "then" of undefined and localhost:3000/[object%20Object] 404 (Not Found)
server.js to call the login endpoint:
app.post('/api/login', authController.login);
Module: this console.log returns on cmd, if I use the full code the api get stuck on pending request, not sure if the code is wrong or mongoDB is just taking long to return me the username and password.
module.exports.login = function (req, res){
res.send('test'); // is okay
User.find(req.body, function(err, results){
if(err){
console.log('Fail to login')
}
if(results && results.lenght ===1){
res.json(req.body.username);
}
})
}
html:
<input type="text" class="form-control" id="username"
placeholder="Username" ng-model="vm.userlogin.username">
<input type="password" class="form-control" id="exampleInputPassword1"
placeholder="Password" ng-model="vm.userlogin.password">
<button type="submit" class="btn btn-default"
ng-click="vm.loginUser()">Submit</button>