I'm currently trying to intergrate a login API with my angular JS app for authentication.
This is my current login function:
var $promise = $http.post(API + '/login', {
username: name,
password: pw
});
$promise.then(function(msg){
if(msg.data.success == true){
resolve('Login success.');
}else{
reject('Login Failed.');
}
});
It's successfully returning when successful, however when I try to GET the settings from the user using the API I'm getting an error for unauthorization.
This is my GET request:
$http({
method: 'GET',
url: API + '/account/settings',
withCredentials: true
}).then(function successCallback(response) {
// SUCCESS
}, function errorCallback(response) {
// ERROR
});
It's really, really puzzling me. I can use Postman to make the API call to login and then GET from the settings, but can't for the life of me get this working.
These are my response headers from the LOGIN request:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:8100
Connection:keep-alive
Content-Length:171
Content-Type:application/json; charset=utf-8
Date:Tue, 20 Dec 2016 21:30:05 GMT
ETag:W/"ab-vCrnhzn26fE4borN6cmpAw"
set-cookie:connect.sid=s%3A1EF4OfHQ2uYb750QvccZB4pnNCyTsAfd.ISmVn3vE5jXjEwmLbtsQK4O339%2Fw74K3Y613f4%2FcTKE; Path=/; HttpOnly
Vary:Origin, X-HTTP-Method-Override, Accept-Encoding