export default function ({ $axios, redirect, app, store }, inject) { // Create a custom axios instance const apis = $axios.create({ // headers: { // common: { // Accept: 'text/plain, */*' // } // }, baseURL: '/apis', timeout: 10000, withCredentials: true }) apis.onRequest(config => { if (store.state.token) { config.headers.authorization = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwLnNlZWNvZGVyLmNuIiwic3ViIjoiMTc3NjE3MDgxODEiLCJhdWQiOiJzZWVjLW1vb2MiLCJhdXRoX3RpbWUiOjE2MjI2OTAyMTQsImlhdCI6MTYyMjY5MDIxNCwiZXhwIjoxNjIyNzc2NjE0LCJ1c2VyX2luZm8iOnsicGhvbmUiOiIxNzc2MTcwODE4MSIsImVtYWlsIjoiMTE1ODQ5NDMxOEBxcS5jb20iLCJpZCI6MTM3MiwibmFtZSI6ImxpaGUiLCJyb2xlIjoiU1RVREVOVCJ9fQ.y4dY0BFMvK13W43BZQ3DWSf5ppnq1k4ycFwudp9EKRY" } else { delete config.headers.authorization } return config }) apis.setHeader('Content-Type', 'application/json') apis.onResponse(response => { if (response.status === 401) { store.commit('saveToken', null) store.commit('saveUser', {}) redirect('/unauthorized') } }) apis.onError(error => { if (error.response.status === 401) { store.commit('saveToken', null) store.commit('saveUser', {}) redirect('/unauthorized') } }) // Inject to context as $apis inject('apis', apis) }