I'm using Axios
for sending http requests, it's working fine for Android, but the headers are not sent in iOS, here is my code:
Axios.get('/patient/doctor/search?page_size=10&page=1')
.then(function (response) {
// handle response
})
.catch(function (error) {
// here it goes with 401 error code
});
and in my interceptor:
Axios.interceptors.request.use(async config => {
try {
const user = await AsyncStorage.getItem('user');
const userData = JSON.parse(user);
if (userData.token) {
config.headers = {
ContentType: 'application/json',
Authorization: 'Bearer [JWT-TOKEN]'
}
} else {
config.headers = {
ContentType: 'application/json'
};
}
} catch (e) {
config.headers = { 'ContentType': 'application/json; charset=utf' };
}
return config;
}, error => {
return Promise.reject(error);
});
Any Idea ?