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