0

i'm new in programming so bear with me. Need some help on calling API using angularjs here, and I think this have some problem with JSON Web Tokens; when trying to calling the API i get:

Login Object {success: true, data: Object}

Object {success: false, error: "User not logged in

        $scope.login = function () {
            var url = "";
            url = 'http://localhost.net/api/login';
            $.post(url, {email: "admin", password: "admin"}, function (data)
            {
                console.log("Login", data);

                url = 'http://localhost.net/api/device/get';
                $.post(url, {}, function (data)
                {
                    console.log("Devices", data);
                }).fail(function (data) {
                    console.log("Devices", "login_failed");
                });

                url = 'http://localhost.net/api/async';
                $.post(url, {}, function (data)
                {
                    console.log("Live Data", data);
                }).fail(function (data) {
                    console.log("Live Data", "login_failed");
                });

                url = 'http://localhost.net/api/command/send';
                $.post(url, {deviceId: 2, type: "Stop"}, function (data)
                {
                    console.log("Command", data);
                }).fail(function (data) {
                    console.log("Command", "login_failed");
                });

            }).fail(function (data) {
                console.log("Login", "login_failed");
            });
        };
1
  • is there a reason you're using jquery post instead of angulars? Commented Oct 17, 2015 at 16:43

2 Answers 2

1

According to this documentation, you're not sending a token along with your JWT request:

https://scontent-ord1-1.xx.fbcdn.net/hphotos-xat1/v/t1.0-9/12109126_10203610003569176_8949255308934231993_n.jpg?oh=778476213b57b2815aadee006fe7cf79&oe=56C3F0FB

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot for showing my mistakes :D really enlighten me
0

The provided code shows no implementation of JWT, and uses the jQuery Ajax system to make it's requests. It's confusing to know where the "JWT Problem" is. Are you using angular-jwt? If so automatic token handling is provided through $http, not $.ajax, which may be your problem. More information about the implementation of that library can be found here

If this isn't the case, I recommend reviewing the implementation described here .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.