feat: local login URL

This commit is contained in:
Reto Aebersold 2023-12-05 09:15:50 +01:00 committed by Christian Cueni
parent 2c5643e929
commit 447ac05859
5 changed files with 32 additions and 10 deletions

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import log from "loglevel"; import log from "loglevel";
import { getLoginURL } from "@/router/utils";
import AccountMenu from "@/components/header/AccountMenu.vue"; import AccountMenu from "@/components/header/AccountMenu.vue";
import MobileMenu from "@/components/header/MobileMenu.vue"; import MobileMenu from "@/components/header/MobileMenu.vue";
import NotificationPopover from "@/components/notifications/NotificationPopover.vue"; import NotificationPopover from "@/components/notifications/NotificationPopover.vue";
@ -275,7 +275,9 @@ onMounted(() => {
</Popover> </Popover>
</div> </div>
<div v-else> <div v-else>
<a class="" :href="`/sso/login?lang=${userStore.language}`">Login</a> <a class="" :href="getLoginURL({ lang: userStore.language })">
Login
</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -18,14 +18,14 @@ async function changeLocale(language: AvailableLanguages) {
<template> <template>
<div class="flex flex-col items-center justify-between space-y-8 bg-blue-900 p-8"> <div class="flex flex-col items-center justify-between space-y-8 bg-blue-900 p-8">
<div class="flex w-full items-center justify-between"> <div class="flex w-full items-center justify-between">
<div class="flex justify-center"> <a href="/" class="flex justify-center">
<div class="h-8 w-16"> <div class="h-8 w-16">
<it-icon-vbv class="-ml-3 -mt-6 mr-3 h-8 w-16" /> <it-icon-vbv class="-ml-3 -mt-6 mr-3 h-8 w-16" />
</div> </div>
<div class="ml-1 border-l border-white pl-3 text-2xl text-white"> <div class="ml-1 border-l border-white pl-3 text-2xl text-white">
{{ $t("general.title") }} {{ $t("general.title") }}
</div> </div>
</div> </a>
<Menu as="div" class="relative block text-left"> <Menu as="div" class="relative block text-left">
<div class="text-white"> <div class="text-white">
<MenuButton class="text-white"> <MenuButton class="text-white">

View File

@ -1,6 +1,7 @@
<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";
const props = defineProps({ const props = defineProps({
courseType: { courseType: {
@ -27,7 +28,7 @@ const user = useUserStore();
<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="`/sso/login?course=${props.courseType}&lang=${user.language}`" :href="getLoginURL({ course: props.courseType, lang: user.language })"
class="btn-secondary" class="btn-secondary"
> >
{{ $t("a.Anmelden") }} {{ $t("a.Anmelden") }}

View File

@ -1,3 +1,4 @@
import { getLoginURLNext, shouldUseSSO } from "@/router/utils";
import { useCourseSessionsStore } from "@/stores/courseSessions"; import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import type { NavigationGuard, RouteLocationNormalized } from "vue-router"; import type { NavigationGuard, RouteLocationNormalized } from "vue-router";
@ -21,14 +22,13 @@ export const redirectToLoginIfRequired: NavigationGuard = (to, from, next) => {
} }
if (loginRequired(to) && !user.loggedIn) { if (loginRequired(to) && !user.loggedIn) {
const appEnv = import.meta.env.VITE_APP_ENVIRONMENT || "local"; const loginURL = getLoginURLNext();
const ssoLogin = appEnv.startsWith("prod") || appEnv.startsWith("stage"); if (shouldUseSSO()) {
if (ssoLogin) {
// Redirect to SSO login page, handled by the server // Redirect to SSO login page, handled by the server
window.location.href = `/sso/login/?next=${encodeURIComponent(to.fullPath)}`; window.location.href = loginURL;
} else { } else {
// Handle local login with Vue router // Handle local login with Vue router
next(`/login-local?next=${encodeURIComponent(to.fullPath)}`); next(loginURL);
} }
} else { } else {
// If login is not required or user is already logged in, continue with the navigation // If login is not required or user is already logged in, continue with the navigation

View File

@ -0,0 +1,19 @@
export function shouldUseSSO() {
const appEnv = import.meta.env.VITE_APP_ENVIRONMENT || "local";
return appEnv.startsWith("prod") || appEnv.startsWith("stage");
}
export function getLoginURL(params = {}) {
let url = shouldUseSSO() ? "/sso/login/" : "/login-local";
const queryParams = new URLSearchParams(params);
if (queryParams.toString()) {
url += `?${queryParams}`;
}
return url;
}
export function getLoginURLNext() {
return getLoginURL({ next: window.location.pathname });
}