Compare commits

...

3 Commits

3 changed files with 15 additions and 13 deletions

View File

@ -52,9 +52,15 @@ 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 {getAuthForRoute} from '@/router'
const router = useRouter()
const route = useRoute()
const store = useStore() const store = useStore()
const ready = computed(() => store.state.vikunjaReady) const ready = ref(false)
const online = useOnline() const online = useOnline()
const error = ref('') const error = ref('')
@ -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 = getAuthForRoute(route)
if (typeof redirectTo !== 'undefined') {
await router.push(redirectTo)
}
ready.value = true
} catch (e: any) {
error.value = e error.value = e
} }
} }

View File

@ -575,11 +575,7 @@ const router = createRouter({
], ],
}) })
router.beforeEach((to) => { export function getAuthForRoute(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']

View File

@ -43,7 +43,6 @@ export const store = createStore({
menuActive: true, menuActive: true,
keyboardShortcutsActive: false, keyboardShortcutsActive: false,
quickActionsActive: false, quickActionsActive: false,
vikunjaReady: false,
}, },
mutations: { mutations: {
[LOADING](state, loading) { [LOADING](state, loading) {
@ -79,9 +78,6 @@ export const store = createStore({
[BACKGROUND](state, background) { [BACKGROUND](state, background) {
state.background = background state.background = background
}, },
vikunjaReady(state, ready) {
state.vikunjaReady = ready
},
}, },
actions: { actions: {
async [CURRENT_LIST]({state, commit}, currentList) { async [CURRENT_LIST]({state, commit}, currentList) {
@ -136,10 +132,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)
}, },
}, },
}) })