I think i deal with some basic thing but dispite that I am not able to solve this alone.
In Angular Documentation I foundout option how to set header for each request. It should be something like:
module.run(function($http) {
$http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
});
This looks find if you know token from start as in this example. But i get user token after he login.
So I try something like:
login: function(email, password) {
var data = {'userName':email, 'password': password};
$http.post('api/v1/users/login.php', data).then(function (res) {
$cookies.put('user', res.data);
$http.defaults.headers.common.Authorization = 'Bearer '+res.data.token;
});
}
This now added Authorization header to each request but just inside of LoginCtrl. If I make request in any other controller its without this header.
As soon as I create other $http request in other controllers I need it work there. Is there some nice way how to set it for each controller or I have to set it at load of each controller from cookie?