Skip to content

Instantly share code, notes, and snippets.

@xmanemran
Created April 26, 2021 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmanemran/9ddfc44f50bd04967e63aca8f83fd05d to your computer and use it in GitHub Desktop.
Save xmanemran/9ddfc44f50bd04967e63aca8f83fd05d to your computer and use it in GitHub Desktop.
import axios from 'axios';
export const BASE_URL = '';
export const PAGE_LIMIT = 10;
const instance = axios.create({
baseURL: `${BASE_URL}/v1`,
timeout: 100000,
});
instance.interceptors.response.use(
function (config) {
config.status = 401
window.location = '/login'
},
function (error) {
// Do something with request error
return Promise.reject(error);
},
);
export const httpAuth = axios.create({
baseURL: `${BASE_URL}/auth`,
timeout: 100000,
});
export const setHttpToken = token => {
instance.defaults.headers.common['token'] = token;
};
export const removeHttpToken = () => {
instance.defaults.headers.common['token'] = null;
};
export default instance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment