Reputation: 29
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");
});
};
Upvotes: 0
Views: 74
Reputation: 320
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 .
Upvotes: 0
Reputation: 162
According to this documentation, you're not sending a token along with your JWT request:
Upvotes: 1