added login stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-06 01:43:47 +01:00
parent 0a09a1b0b7
commit 633f2af5eb
11 changed files with 255 additions and 33 deletions

View File

@@ -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')