diff --git a/frontend/src/boot/axios.ts b/frontend/src/boot/axios.ts index 1e22234..53f50c1 100644 --- a/frontend/src/boot/axios.ts +++ b/frontend/src/boot/axios.ts @@ -1,5 +1,6 @@ import { boot } from 'quasar/wrappers'; import axios, { AxiosInstance } from 'axios'; +import {router} from 'src/router'; declare module '@vue/runtime-core' { interface ComponentCustomProperties { @@ -15,7 +16,23 @@ declare module '@vue/runtime-core' { // "export default () => {}" function below (which runs individually // for each client) const api:AxiosInstance = axios.create({ baseURL: process.env.KAB_BACKEND_URL }); - +const token=localStorage.getItem('token')||''; +if(token!==''){ + api.defaults.headers["Authorization"]='Bearer ' + token; +} +api.interceptors.response.use( + (response)=>response, + (error)=>{ + const orgReq=error.config; + if(error.response && error.response.status===401){ + localStorage.removeItem('token'); + router.replace({ + path:"/login", + query:{redirect:router.currentRoute.value.fullPath} + }); + } + } +) export default boot(({ app }) => { // for use inside Vue files (Options API) through this.$axios and this.$api diff --git a/frontend/src/components/AppSelect.vue b/frontend/src/components/AppSelect.vue index 79d0452..809c6a7 100644 --- a/frontend/src/components/AppSelect.vue +++ b/frontend/src/components/AppSelect.vue @@ -1,11 +1,20 @@ - + diff --git a/frontend/src/components/FieldSelect.vue b/frontend/src/components/FieldSelect.vue index 7f319f8..66fdc66 100644 --- a/frontend/src/components/FieldSelect.vue +++ b/frontend/src/components/FieldSelect.vue @@ -1,6 +1,6 @@