So, I have an Ionic app that requires a FB login, all is good but what I need to do is add 2 custom headers to every API request. Again, this should work... The issue I am having is that for some reason I am unable to grab the 'fbtoken' that is set on successful login. Here is some code:
LoginController:
OpenFB.login('email, user_friends').then(
function () {
OpenFB.get('/me').success(function (user) {
$localStorage.fbuser = user; //Set the user in local storage.
});
RequestService.get($scope.baseUrl + 'user')
.success(function(data, status, headers, config){
alert('Success!!!! ' + data);
}).error(function(data, status, headers, config){
if(status = 401) alert('Not Authorized!');
});
},
function (error) {
alert('OpenFB login failed' + error);
});
};
app.js
.config(function($stateProvider, $urlRouterProvider, $httpProvider) {
$httpProvider.interceptors.push(function($q, $localStorage) {
console.log($localStorage);
return {
'request': function(config) {
config.headers['Auth-Token'] = JSON.parse(localStorage.get("fbtoken"));
config.headers['Auth-Provider'] = 'facebook';
return config;
}
};
});
});
I can access the fbuser from local storage that is being set in the controller. The only difference between fbuser & fbtoken if I take a look in Chrome Inspector is that the names are different:
fbtoken
ngStorage-fbuser
Is this the issue? can I get the value of fbtoken in to my inceptor?
Ok, so rather than using ngStorage module, I decided to go native JS and ran localStorage.setItem(option, value)
& localStorage.getItem(option)