Created
April 26, 2021 11:30
-
-
Save xmanemran/9ddfc44f50bd04967e63aca8f83fd05d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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