From e9b9c8856a8643f88ab1db630a92fcbe4f569148 Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Tue, 3 Dec 2024 14:35:04 +0100 Subject: [PATCH] Attempt 2 to fix codefactor complexity test --- .../(authentication)/login/+page.server.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/frontend/src/routes/(authentication)/login/+page.server.ts b/frontend/src/routes/(authentication)/login/+page.server.ts index 83b4235c83..92b7d3b40c 100644 --- a/frontend/src/routes/(authentication)/login/+page.server.ts +++ b/frontend/src/routes/(authentication)/login/+page.server.ts @@ -1,7 +1,8 @@ import { getSecureRedirect } from '$lib/utils/helpers'; import { ALLAUTH_API_URL, BASE_API_URL } from '$lib/utils/constants'; -import { CI_TEST } from '$lib/utils/env_constants'; +// The CI_TEST environment variable will have to be removed if the `currentLang == preferedLang` solution fix the enterprise function tests. +// import { CI_TEST } from '$lib/utils/env_constants'; import { loginSchema } from '$lib/utils/schemas'; import type { LoginRequestBody } from '$lib/utils/types'; import { fail, redirect, type Actions } from '@sveltejs/kit'; @@ -26,6 +27,15 @@ interface AuthenticationFlow { types: 'totp' | 'recovery_codes'; } +function makeRedirectURL(currentLang: string, preferedLang: string, url: URL): string { + const next = url.searchParams.get('next') || '/'; + const secureNext = getSecureRedirect(next); + if (currentLang == preferedLang) { + return secureNext; + } + return secureNext ? `${secureNext}?refresh=1` : `/?refresh=1`; +} + export const load: PageServerLoad = async ({ fetch, request, locals }) => { // redirect user if already logged in if (locals.user) { @@ -129,16 +139,7 @@ export const actions: Actions = { }); } - const next = url.searchParams.get('next') || '/'; - const secureNext = getSecureRedirect(next); - const refreshQueryParam = CI_TEST ? '' : '?refresh=1'; - // The CI_TEST environment variable will have to be removed if the `currentLang == preferedLang` solution fix the enterprise function tests. - if (currentLang == preferedLang) { - redirect(302, secureNext); - } - - const redirectURL = secureNext ? `${secureNext}${refreshQueryParam}` : `/${refreshQueryParam}`; - redirect(302, redirectURL); + redirect(302, makeRedirectURL(currentLang, preferedLang, url)); }, mfaAuthenticate: async (event) => { const formData = await event.request.formData();