fix: make sure the app is fully ready before trying to redirect to the login page
This commit is contained in:
parent
68a76faacc
commit
55826bb8c9
3 changed files with 14 additions and 8 deletions
|
@ -52,6 +52,12 @@ import NoAuthWrapper from '@/components/misc/no-auth-wrapper.vue'
|
||||||
import {ERROR_NO_API_URL} from '@/helpers/checkAndSetApiUrl'
|
import {ERROR_NO_API_URL} from '@/helpers/checkAndSetApiUrl'
|
||||||
import {useOnline} from '@/composables/useOnline'
|
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 store = useStore()
|
||||||
|
|
||||||
const ready = computed(() => store.state.vikunjaReady)
|
const ready = computed(() => store.state.vikunjaReady)
|
||||||
|
@ -63,7 +69,12 @@ const showLoading = computed(() => !ready.value && error.value === '')
|
||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
await store.dispatch('loadApp')
|
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
|
error.value = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -575,11 +575,7 @@ const router = createRouter({
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach((to) => {
|
export function checkAuth(route: RouteLocation) {
|
||||||
return checkAuth(to)
|
|
||||||
})
|
|
||||||
|
|
||||||
function checkAuth(route: RouteLocation) {
|
|
||||||
const authUser = store.getters['auth/authUser']
|
const authUser = store.getters['auth/authUser']
|
||||||
const authLinkShare = store.getters['auth/authLinkShare']
|
const authLinkShare = store.getters['auth/authLinkShare']
|
||||||
|
|
||||||
|
|
|
@ -136,10 +136,9 @@ export const store = createStore({
|
||||||
|
|
||||||
commit(CURRENT_LIST, currentList)
|
commit(CURRENT_LIST, currentList)
|
||||||
},
|
},
|
||||||
async loadApp({commit, dispatch}) {
|
async loadApp({dispatch}) {
|
||||||
await checkAndSetApiUrl(window.API_URL)
|
await checkAndSetApiUrl(window.API_URL)
|
||||||
await dispatch('auth/checkAuth')
|
await dispatch('auth/checkAuth')
|
||||||
commit('vikunjaReady', true)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue