fix(portal): separate login from navigation error handling

Move router.replace() outside the login try/catch so navigation
failures (e.g. stale Vite HMR dynamic imports) don't mask a
successful login. Falls back to window.location on nav error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 08:55:38 +02:00
parent 5173f7297f
commit 8f1b53130b

View File

@@ -57,8 +57,6 @@ async function onSubmit(): Promise<void> {
try { try {
await authStore.login(form.value.email.trim(), form.value.password) await authStore.login(form.value.email.trim(), form.value.password)
await portalStore.hydrateAfterAuth() await portalStore.hydrateAfterAuth()
const redirect = typeof route.query.to === 'string' ? route.query.to : '/dashboard'
await router.replace(redirect || '/dashboard')
} }
catch (error: unknown) { catch (error: unknown) {
if (error instanceof Error && error.message === 'Sessie kon niet worden gestart.') { if (error instanceof Error && error.message === 'Sessie kon niet worden gestart.') {
@@ -68,10 +66,20 @@ async function onSubmit(): Promise<void> {
} }
const ax = error as { response?: { data?: { message?: string } } } const ax = error as { response?: { data?: { message?: string } } }
errorMessage.value = mapLoginErrorMessage(ax.response?.data?.message) errorMessage.value = mapLoginErrorMessage(ax.response?.data?.message)
return
} }
finally { finally {
isSubmitting.value = false isSubmitting.value = false
} }
// Navigate after login — outside try/catch so navigation errors
// (e.g. stale dynamic imports) don't mask a successful login.
const redirect = typeof route.query.to === 'string' ? route.query.to : '/dashboard'
router.replace(redirect || '/dashboard').catch(() => {
// Dynamic import can fail after Vite HMR; a full reload recovers.
window.location.href = redirect || '/dashboard'
})
} }
</script> </script>