Changeset View
Changeset View
Standalone View
Standalone View
src/resources/vue/components/App.vue
<template> | <template> | ||||
<router-view></router-view> | <router-view></router-view> | ||||
</template> | </template> | ||||
<script> | <script> | ||||
import store from '../js/store' | |||||
export default { | export default { | ||||
created() { | created() { | ||||
if (localStorage.token) { | if (localStorage.token) { | ||||
axios.get('/api/auth/info', { | axios.defaults.headers.common.Authorization = 'Bearer ' + localStorage.getItem('token') | ||||
headers: { | |||||
Authorization: 'Bearer ' + localStorage.getItem('token') | axios.get('/api/auth/info').then(response => { | ||||
} | this.$root.loginUser(localStorage.getItem('token')) | ||||
}).then(response => { | |||||
store.commit('loginUser') | |||||
}).catch(error => { | }).catch(error => { | ||||
if (error.response.status === 401 || error.response.status === 403) { | if (error.response.status === 401 || error.response.status === 403) { | ||||
store.commit('logoutUser') | this.$root.logoutUser() | ||||
localStorage.setItem('token', '') | |||||
this.$router.push({name: 'login'}) | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
</script> | </script> |