Skip to content

Commit

Permalink
Attempt 2 to fix codefactor complexity test
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Dec 3, 2024
1 parent 4a54027 commit e9b9c88
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions frontend/src/routes/(authentication)/login/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e9b9c88

Please sign in to comment.