From c4b92a8f52f1f46966b64b0142a121572c55be94 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 16 May 2020 12:02:30 +0200 Subject: [PATCH] Fix redirect when not logged in --- src/App.vue | 34 ++++++++++++++++++---------------- src/store/modules/auth.js | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/App.vue b/src/App.vue index 0ca0f35eb..ae177aa17 100644 --- a/src/App.vue +++ b/src/App.vue @@ -264,25 +264,27 @@ } }, beforeCreate() { - // Check if the user is already logged in, if so, redirect them to the homepage - if ( - !this.userAuthenticated && - this.$route.name !== 'login' && - this.$route.name !== 'getPasswordReset' && - this.$route.name !== 'passwordReset' && - this.$route.name !== 'register' && - this.$route.name !== 'linkShareAuth' - ) { - router.push({name: 'login'}) - } - }, - created() { this.$store.dispatch('config/update') this.$store.dispatch('auth/checkAuth') + .then(() => { + // Check if the user is already logged in, if so, redirect them to the homepage + if ( + !this.userAuthenticated && + this.$route.name !== 'login' && + this.$route.name !== 'getPasswordReset' && + this.$route.name !== 'passwordReset' && + this.$route.name !== 'register' && + this.$route.name !== 'linkShareAuth' + ) { + router.push({name: 'login'}) + } - if (this.userAuthenticated && this.userInfo.type === authTypes.USER && (this.$route.params.name === 'home' || this.namespaces.length === 0)) { - this.loadNamespaces() - } + if (this.userAuthenticated && this.userInfo.type === authTypes.USER && (this.$route.params.name === 'home' || this.namespaces.length === 0)) { + this.loadNamespaces() + } + }) + }, + created() { // Service worker communication document.addEventListener(swEvents.SW_UPDATED, this.showRefreshUI, {once: true}) diff --git a/src/store/modules/auth.js b/src/store/modules/auth.js index 75dbe531b..d991c1535 100644 --- a/src/store/modules/auth.js +++ b/src/store/modules/auth.js @@ -119,6 +119,7 @@ export default { ctx.commit('info', info) } ctx.commit('authenticated', authenticated) + return Promise.resolve() }, // Renews the api token and saves it to local storage renewToken(ctx) {