Implemented login/logout
This commit is contained in:
29
src/App.vue
29
src/App.vue
@@ -31,9 +31,34 @@ export default {
|
||||
},
|
||||
created() {
|
||||
// The basic app is created... Currently showing a loading screen (as soon as mounted)
|
||||
this.$store.dispatch('storeUserData','testuser').then(() => {
|
||||
|
||||
if (this.$api.haveToken) {
|
||||
|
||||
this.$api.getMyInfo().then(({name}) => {
|
||||
|
||||
this.$store.dispatch('storeUserData', name).then(() => {
|
||||
this.$router.push('/').catch(() => {});
|
||||
this.$store.dispatch('setAppReady');
|
||||
|
||||
});
|
||||
|
||||
}).catch(({status, text}) => {
|
||||
if (status === 401) {
|
||||
this.$api.clearTokenFromLocalStorage();
|
||||
this.$router.push('/login').catch(() => {});
|
||||
this.$store.dispatch('setAppReady');
|
||||
|
||||
} else {
|
||||
this.$showToast(text);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
this.$router.push('/login').catch(() => {});
|
||||
this.$store.dispatch('setAppReady');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user