naise-pos-android-mobile/src/constants/http-request.js
Andi Firwansyah 2acb336744 init
2022-11-27 19:26:04 +07:00

47 lines
976 B
JavaScript

import Axios from 'axios';
import AsyncStorage from '@react-native-async-storage/async-storage';
Axios.interceptors.request.use(
async config => {
const token = await AsyncStorage.getItem('userToken');
console.log('token ', token);
if (token) {
config.headers.Authorization = 'Bearer ' + token;
}
return config;
},
error => {
return Promise.reject(error);
},
);
export const get = async (url, config = null) => {
return Axios.get(url, config)
.then(response => {
return response;
})
.catch(err => {
return err;
});
};
export const post = (url, data, config = null) => {
return Axios.post(url, data, config)
.then(response => {
return response;
})
.catch(err => {
return err;
});
};
export const put = (url, data, config = null) => {
return Axios.put(url, data, config)
.then(response => {
return response;
})
.catch(err => {
return err;
});
};