mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-07-10 16:44:26 -05:00
fix: avoid clearing saved redirect in onBeforeMount to prevent race with submit
When Login.vue re-mounts inside the authenticated layout after a
successful login, its onBeforeMount hook fires again. If it calls
redirectIfSaved(), it clears the saved route from localStorage before
the submit() handler's redirectIfSaved() can use it, causing a redirect
to home instead of the saved route. Use router.push({name: 'home'})
directly since the only purpose here is to redirect already-authenticated
users away from the login page.
This commit is contained in:
@@ -125,6 +125,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, onBeforeMount, ref} from 'vue'
|
import {computed, onBeforeMount, ref} from 'vue'
|
||||||
import {useI18n} from 'vue-i18n'
|
import {useI18n} from 'vue-i18n'
|
||||||
|
import {useRouter} from 'vue-router'
|
||||||
import {useDebounceFn} from '@vueuse/core'
|
import {useDebounceFn} from '@vueuse/core'
|
||||||
|
|
||||||
import Message from '@/components/misc/Message.vue'
|
import Message from '@/components/misc/Message.vue'
|
||||||
@@ -143,6 +144,7 @@ import {useTitle} from '@/composables/useTitle'
|
|||||||
const {t} = useI18n({useScope: 'global'})
|
const {t} = useI18n({useScope: 'global'})
|
||||||
useTitle(() => t('user.auth.login'))
|
useTitle(() => t('user.auth.login'))
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const configStore = useConfigStore()
|
const configStore = useConfigStore()
|
||||||
const {redirectIfSaved} = useRedirectToLastVisited()
|
const {redirectIfSaved} = useRedirectToLastVisited()
|
||||||
@@ -171,9 +173,13 @@ onBeforeMount(() => {
|
|||||||
errorMessage.value = e.message
|
errorMessage.value = e.message
|
||||||
})
|
})
|
||||||
|
|
||||||
// Check if the user is already logged in, if so, redirect them to the homepage
|
// Check if the user is already logged in, if so, redirect them to the homepage.
|
||||||
|
// We intentionally use router.push here instead of redirectIfSaved() because
|
||||||
|
// this hook also fires when Login.vue re-mounts inside the authenticated layout
|
||||||
|
// after a successful login. Using redirectIfSaved() here would clear the saved
|
||||||
|
// route before the submit() handler gets a chance to use it.
|
||||||
if (authenticated.value) {
|
if (authenticated.value) {
|
||||||
redirectIfSaved()
|
router.push({name: 'home'})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user