Redirect after login and register

This commit is contained in:
2025-08-05 23:40:46 +02:00
parent dc42258010
commit eac877752f
2 changed files with 22 additions and 4 deletions
+11 -2
View File
@@ -6,6 +6,7 @@ definePageMeta({
}); });
const { fetch } = useUserSession(); const { fetch } = useUserSession();
const router = useRouter(); const router = useRouter();
const route = useRoute();
const localePath = useLocalePath(); const localePath = useLocalePath();
const { isValid, resetValidation, validate } = useForm('formRef'); const { isValid, resetValidation, validate } = useForm('formRef');
const validation = useValidation(); const validation = useValidation();
@@ -28,7 +29,15 @@ async function submit() {
body: form body: form
}); });
await fetch(); await fetch();
await router.push(localePath('/')); await router.push(
localePath(
(route.query.to
? typeof route.query.to === 'string'
? route.query.to
: route.query.to[0]
: '/') || '/'
)
);
return; return;
} catch (e) { } catch (e) {
if (e instanceof Error && 'statusCode' in e && e.statusCode === 404) { if (e instanceof Error && 'statusCode' in e && e.statusCode === 404) {
@@ -118,7 +127,7 @@ async function submit() {
$t('auth.login') $t('auth.login')
}}</VaButton> }}</VaButton>
<VaButton <VaButton
:to="$localePath('/register')" :to="$localePath({ path: '/register', query: route.query })"
border-color="primary" border-color="primary"
preset="secondary" preset="secondary"
>{{ $t('auth.register_instead') }}</VaButton >{{ $t('auth.register_instead') }}</VaButton
+11 -2
View File
@@ -7,6 +7,7 @@ definePageMeta({
}); });
const { fetch } = useUserSession(); const { fetch } = useUserSession();
const router = useRouter(); const router = useRouter();
const route = useRoute();
const localePath = useLocalePath(); const localePath = useLocalePath();
const { isValid, resetValidation, validate } = useForm('formRef'); const { isValid, resetValidation, validate } = useForm('formRef');
const validation = useValidation(); const validation = useValidation();
@@ -30,7 +31,15 @@ async function submit() {
body: form body: form
}); });
await fetch(); await fetch();
await router.push(localePath('/')); await router.push(
localePath(
(route.query.to
? typeof route.query.to === 'string'
? route.query.to
: route.query.to[0]
: '/') || '/'
)
);
return; return;
} catch (e) { } catch (e) {
if (e instanceof Error && 'statusCode' in e && e.statusCode === 409) { if (e instanceof Error && 'statusCode' in e && e.statusCode === 409) {
@@ -150,7 +159,7 @@ async function submit() {
$t('auth.register') $t('auth.register')
}}</VaButton> }}</VaButton>
<VaButton <VaButton
:to="$localePath('/login')" :to="$localePath({ path: '/login', query: route.query })"
border-color="primary" border-color="primary"
preset="secondary" preset="secondary"
>{{ $t('auth.login_instead') }}</VaButton >{{ $t('auth.login_instead') }}</VaButton