Files
crater/resources/scripts/plugins/axios.js
Mohit Panjwani bdea879273 v6 update
2022-01-10 16:06:17 +05:30

32 lines
607 B
JavaScript

import axios from 'axios'
import Ls from '@/scripts/services/ls.js'
window.Ls = Ls
window.axios = axios
axios.defaults.withCredentials = true
axios.defaults.headers.common = {
'X-Requested-With': 'XMLHttpRequest',
}
/**
* Interceptors
*/
axios.interceptors.request.use(function (config) {
// Pass selected company to header on all requests
const companyId = Ls.get('selectedCompany')
const authToken = Ls.get('auth.token')
if (authToken) {
config.headers.common.Authorization = authToken
}
if (companyId) {
config.headers.common['company'] = companyId
}
return config
})