From 55826bb8c9cdc2dffb409e51a3fc1eed967da99b Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 8 Jan 2022 15:44:33 +0100 Subject: [PATCH 1/3] fix: make sure the app is fully ready before trying to redirect to the login page --- src/components/misc/ready.vue | 13 ++++++++++++- src/router/index.ts | 6 +----- src/store/index.js | 3 +-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/misc/ready.vue b/src/components/misc/ready.vue index 07ee0ffa4..fd5fe92d8 100644 --- a/src/components/misc/ready.vue +++ b/src/components/misc/ready.vue @@ -52,6 +52,12 @@ import NoAuthWrapper from '@/components/misc/no-auth-wrapper.vue' import {ERROR_NO_API_URL} from '@/helpers/checkAndSetApiUrl' import {useOnline} from '@/composables/useOnline' +import {useRouter, useRoute} from 'vue-router' +import {checkAuth} from '@/router' + +const router = useRouter() +const route = useRoute() + const store = useStore() const ready = computed(() => store.state.vikunjaReady) @@ -63,7 +69,12 @@ const showLoading = computed(() => !ready.value && error.value === '') async function load() { try { await store.dispatch('loadApp') - } catch(e: any) { + const redirectTo = checkAuth(route) + if (typeof redirectTo !== 'undefined') { + await router.push(redirectTo) + } + store.commit('vikunjaReady', true) + } catch (e: any) { error.value = e } } diff --git a/src/router/index.ts b/src/router/index.ts index 7b28a509c..3f999c700 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -575,11 +575,7 @@ const router = createRouter({ ], }) -router.beforeEach((to) => { - return checkAuth(to) -}) - -function checkAuth(route: RouteLocation) { +export function checkAuth(route: RouteLocation) { const authUser = store.getters['auth/authUser'] const authLinkShare = store.getters['auth/authLinkShare'] diff --git a/src/store/index.js b/src/store/index.js index 37c74ae8e..2b4663bff 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -136,10 +136,9 @@ export const store = createStore({ commit(CURRENT_LIST, currentList) }, - async loadApp({commit, dispatch}) { + async loadApp({dispatch}) { await checkAndSetApiUrl(window.API_URL) await dispatch('auth/checkAuth') - commit('vikunjaReady', true) }, }, }) -- 2.40.1 From dfa30258aa3ee725c94af584e22d39c046cd5d10 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 1 Feb 2022 21:25:42 +0100 Subject: [PATCH 2/3] chore: rename function --- src/components/misc/ready.vue | 4 ++-- src/router/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/misc/ready.vue b/src/components/misc/ready.vue index fd5fe92d8..f94a413e8 100644 --- a/src/components/misc/ready.vue +++ b/src/components/misc/ready.vue @@ -53,7 +53,7 @@ import {ERROR_NO_API_URL} from '@/helpers/checkAndSetApiUrl' import {useOnline} from '@/composables/useOnline' import {useRouter, useRoute} from 'vue-router' -import {checkAuth} from '@/router' +import {getAuthForRoute} from '@/router' const router = useRouter() const route = useRoute() @@ -69,7 +69,7 @@ const showLoading = computed(() => !ready.value && error.value === '') async function load() { try { await store.dispatch('loadApp') - const redirectTo = checkAuth(route) + const redirectTo = getAuthForRoute(route) if (typeof redirectTo !== 'undefined') { await router.push(redirectTo) } diff --git a/src/router/index.ts b/src/router/index.ts index 3f999c700..17d66ba5f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -575,7 +575,7 @@ const router = createRouter({ ], }) -export function checkAuth(route: RouteLocation) { +export function getAuthForRoute(route: RouteLocation) { const authUser = store.getters['auth/authUser'] const authLinkShare = store.getters['auth/authLinkShare'] -- 2.40.1 From 24a154422d8d0112e64eef5da70bf92cf0c44abf Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Tue, 1 Feb 2022 23:09:41 +0100 Subject: [PATCH 3/3] chore: remove vikunjaReady from store --- src/components/misc/ready.vue | 4 ++-- src/store/index.js | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/misc/ready.vue b/src/components/misc/ready.vue index f94a413e8..8fd3f4fd3 100644 --- a/src/components/misc/ready.vue +++ b/src/components/misc/ready.vue @@ -60,7 +60,7 @@ const route = useRoute() const store = useStore() -const ready = computed(() => store.state.vikunjaReady) +const ready = ref(false) const online = useOnline() const error = ref('') @@ -73,7 +73,7 @@ async function load() { if (typeof redirectTo !== 'undefined') { await router.push(redirectTo) } - store.commit('vikunjaReady', true) + ready.value = true } catch (e: any) { error.value = e } diff --git a/src/store/index.js b/src/store/index.js index 2b4663bff..f0d250c13 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -43,7 +43,6 @@ export const store = createStore({ menuActive: true, keyboardShortcutsActive: false, quickActionsActive: false, - vikunjaReady: false, }, mutations: { [LOADING](state, loading) { @@ -79,9 +78,6 @@ export const store = createStore({ [BACKGROUND](state, background) { state.background = background }, - vikunjaReady(state, ready) { - state.vikunjaReady = ready - }, }, actions: { async [CURRENT_LIST]({state, commit}, currentList) { -- 2.40.1