Comments (3)
I am stuck at the same point. Have you found any solutions?
from mean-machine-code.
I figured it out. The problem is with Promises in mongoose new version. So if you use mongoose version ~3.8.19, and then use .success instead of .then in your controllers, it will work fine. I am copying my package.js here.
{
"name": "node-api",
"main": "server.js",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "~1.9.3",
"express": "~4.10.3",
"jsonwebtoken": "^1.2.0",
"mongoose": "~3.8.19",
"morgan": "~1.5.0"
}
}
Here is the live version on heroku:
https://user-crm-420.herokuapp.com/
from mean-machine-code.
This issue is caused by the fact that the $http...success() method have been changed to the $http...then() method, while the "data" parameter hasn't been changed accordingly.
authService.js
// log a user in
authFactory.login = function(username, password) {
// return the promise object and its data
return $http.post('/api/authenticate', {
username: username,
password: password
})
.then(function(data) {
AuthToken.setToken(data.token);
return data;
});
};
Let's compare the 3 versions of the official documents of "$http":
https://code.angularjs.org/1.3.20/docs/api/ng/service/$http
https://code.angularjs.org/1.4.12/docs/api/ng/service/$http
https://code.angularjs.org/1.5.8/docs/api/ng/service/$http
// Simple GET request example :
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
The "response" parameter in the $http....then() method is different from the "data" parameter in the $http....success() method. The source code should be fixed in this way.
// log a user in
authFactory.login = function (username, password) {
// return the promise object and its data
return $http.post('/api/authenticate', {
username: username,
password: password
})
.then(function (response) {
data = response.data;
AuthToken.setToken(data.token);
return data;
});
};
The mainCtrl.js file should be modified in the same way as well.
You may want to download the zip file from https://app.box.com/s/05qdnk96i6h2084em6koo626pud62hos and try it. Please modify the config.js accordingly.
from mean-machine-code.
Related Issues (20)
- In User CRM chapter, catchall route in server.js is catching requests for js files in index.html HOT 1
- Cannot find module .app/modules/user HOT 6
- Issue with pg. 132 Routing HOT 6
- CH-17: How do I create a new user without an existing one. No token = no user? HOT 4
- Just a little fix on the login spinner in chapter 17 HOT 1
- 'username not found' in chapter 10 HOT 4
- expiresInMinutes is deprecated HOT 1
- TypeError: Auth.getUser(...).success is not a function HOT 1
- Gulp & Linting JS page 235
- Not working with UI-ROUTER HOT 1
- Interceptor not triggered whan comming from /api/whatever
- Cloned the Repository: Ran npm intsall in chapter 17: Still doesn't work HOT 1
- Stuck on API creation HOT 4
- login username on navbar HOT 2
- POST Http Issue
- $http.get and posts
- A bug in authService of the 17-user-crm HOT 1
- angular project issue
- Potential Security Issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mean-machine-code.