feat: pass next to sign-up / login

This commit is contained in:
Reto Aebersold 2023-12-19 15:03:38 +01:00
parent d161696341
commit 3c3dde74b9
2 changed files with 35 additions and 21 deletions

View File

@ -1,7 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import WizardPage from "@/components/onboarding/WizardPage.vue"; import WizardPage from "@/components/onboarding/WizardPage.vue";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import { getLoginURL } from "@/router/utils"; import { getLoginURL, getSignUpURL } from "@/router/utils";
import { useRoute } from "vue-router";
import { computed } from "vue";
const props = defineProps({ const props = defineProps({
courseType: { courseType: {
@ -9,7 +11,27 @@ const props = defineProps({
required: true, required: true,
}, },
}); });
const user = useUserStore(); const user = useUserStore();
const route = useRoute();
function constructParams() {
const params: { lang: string; next?: string; course?: string } = {
lang: user.language,
};
const nextValue = route.query.next;
if (nextValue && typeof nextValue === "string") {
params.next = nextValue;
} else {
params.course = props.courseType;
}
return params;
}
const loginURL = computed(() => getLoginURL(constructParams()));
const signUpURL = computed(() => getSignUpURL(constructParams()));
</script> </script>
<template> <template>
@ -19,23 +41,12 @@ const user = useUserStore();
<p class="mb-4"> <p class="mb-4">
{{ $t("a.Damit du myVBV nutzen kannst, brauchst du ein Konto.") }} {{ $t("a.Damit du myVBV nutzen kannst, brauchst du ein Konto.") }}
</p> </p>
<a <a :href="signUpURL" class="btn-primary">
:href="`/sso/signup?course=${props.courseType}&lang=${user.language}`"
class="btn-primary"
>
{{ $t("a.Konto erstellen") }} {{ $t("a.Konto erstellen") }}
</a> </a>
<p class="mb-4 mt-12">{{ $t("a.Hast du schon ein Konto?") }}</p> <p class="mb-4 mt-12">{{ $t("a.Hast du schon ein Konto?") }}</p>
<a <a :href="loginURL" class="btn-secondary">
:href="
getLoginURL({
course: props.courseType,
lang: user.language,
})
"
class="btn-secondary"
>
{{ $t("a.Anmelden") }} {{ $t("a.Anmelden") }}
</a> </a>
</template> </template>

View File

@ -3,15 +3,18 @@ export function shouldUseSSO() {
return appEnv.startsWith("prod") || appEnv.startsWith("stage"); return appEnv.startsWith("prod") || appEnv.startsWith("stage");
} }
export function getLoginURL(params = {}) { function constructURL(basePath: string, params = {}) {
let url = shouldUseSSO() ? "/sso/login/" : "/login-local";
const queryParams = new URLSearchParams(params); const queryParams = new URLSearchParams(params);
if (queryParams.toString()) { return `${basePath}${queryParams.toString() ? `?${queryParams}` : ""}`;
url += `?${queryParams}`; }
}
return url; export function getLoginURL(params = {}) {
const basePath = shouldUseSSO() ? "/sso/login" : "/login-local";
return constructURL(basePath, params);
}
export function getSignUpURL(params = {}) {
return constructURL("/sso/signup", params);
} }
export function getLoginURLNext() { export function getLoginURLNext() {