2020-10-02 07:13:14 +00:00
|
|
|
import axios, { AxiosInstance } from 'axios';
|
|
|
|
import { boot } from 'quasar/wrappers';
|
2020-10-16 07:38:14 +00:00
|
|
|
import config from '../config';
|
2020-10-18 23:45:06 +00:00
|
|
|
import { Store } from 'vuex';
|
2020-10-29 00:39:06 +00:00
|
|
|
import { StateInterface } from 'src/store';
|
2020-10-02 07:13:14 +00:00
|
|
|
|
|
|
|
declare module 'vue/types/vue' {
|
|
|
|
interface Vue {
|
|
|
|
$axios: AxiosInstance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 00:39:06 +00:00
|
|
|
export default boot<Store<StateInterface>>(({ Vue, store }) => {
|
2020-10-02 07:13:14 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
|
|
Vue.prototype.$axios = axios;
|
2020-10-15 01:35:44 +00:00
|
|
|
axios.defaults.baseURL = config.baseURL;
|
|
|
|
|
2020-10-16 07:38:14 +00:00
|
|
|
axios.interceptors.request.use(config => {
|
2020-10-29 00:39:06 +00:00
|
|
|
const session = store.state.user.session;
|
|
|
|
if (session.token) {
|
2020-10-28 15:54:28 +00:00
|
|
|
config.headers = {'Authorization': 'Token ' + session.token};
|
2020-10-16 07:38:14 +00:00
|
|
|
}
|
|
|
|
return config;
|
|
|
|
});
|
2020-10-02 07:13:14 +00:00
|
|
|
});
|
2020-10-15 09:23:41 +00:00
|
|
|
|
|
|
|
export { axios };
|