This commit is contained in:
24
src/main.js
24
src/main.js
@@ -1,4 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import store from './store'
|
||||
@@ -39,9 +41,29 @@ Vue.use(MdRipple);
|
||||
Vue.use(MdDialog);
|
||||
Vue.use(MdSpeedDial);
|
||||
|
||||
Vue.prototype.$api = axios.create({
|
||||
baseURL: process.env.VUE_APP_API_LOCATION
|
||||
});
|
||||
|
||||
new Vue({
|
||||
router,
|
||||
store,
|
||||
render: h => h(App)
|
||||
render: h => h(App),
|
||||
created() {
|
||||
this.$api.interceptors.response.use(undefined, function (err) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (err.status === 401 && err.config && !err.config.__isRetryRequest) {
|
||||
this.$store.dispatch("performLogout").then(() => {
|
||||
this.$router.push({name: 'Welcome'});
|
||||
});
|
||||
}
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
this.$api.interceptors.request.use((config) => {
|
||||
if (this.$store && this.$store.getters.isLoggedIn) {
|
||||
config.headers["Authorization"] = "Bearer " + this.$store.state.auth.token;
|
||||
}
|
||||
})
|
||||
}
|
||||
}).$mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user