Giter Club home page Giter Club logo

Comments (3)

themodernturing avatar themodernturing commented on July 21, 2024

I am stuck at the same point. Have you found any solutions?

from mean-machine-code.

themodernturing avatar themodernturing commented on July 21, 2024

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.

boxoft avatar boxoft commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.