flaschengeist-frontend/src/boot/axios.ts

28 lines
747 B
TypeScript
Raw Normal View History

2020-10-02 07:13:14 +00:00
import axios, { AxiosInstance } from 'axios';
import { boot } from 'quasar/wrappers';
import { UserStateInterface } from 'src/plugins/user/store/user';
2020-10-16 07:38:14 +00:00
import config from '../config';
import { Store } from 'vuex';
2020-10-02 07:13:14 +00:00
declare module 'vue/types/vue' {
interface Vue {
$axios: AxiosInstance;
}
}
export default boot<Store<any>>(({ 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 => {
const session: Session = store.getters['user/session'];
if (session) {
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 };