From 19368daf5c261645ab83cc8faa3f364a8a370230 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 22 Aug 2023 15:55:53 -0400 Subject: [PATCH] Move function to login-page Signed-off-by: Craig Perkins --- public/apps/login/login-page.tsx | 15 ++++++++++++++- public/utils/login-utils.tsx | 13 ------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/public/apps/login/login-page.tsx b/public/apps/login/login-page.tsx index da8c19495..8968b7582 100644 --- a/public/apps/login/login-page.tsx +++ b/public/apps/login/login-page.tsx @@ -29,7 +29,7 @@ import { import { CoreStart } from '../../../../../src/core/public'; import { ClientConfigType } from '../../types'; import defaultBrandImage from '../../assets/opensearch_logo_h.svg'; -import { validateCurrentPassword, extractNextUrlFromWindowLocation } from '../../utils/login-utils'; +import { validateCurrentPassword } from '../../utils/login-utils'; import { ANONYMOUS_AUTH_LOGIN, AuthType, @@ -61,6 +61,19 @@ function redirect(serverBasePath: string) { window.location.href = nextUrl + window.location.hash; } +function extractNextUrlFromWindowLocation(): string { + const urlParams = new URLSearchParams(window.location.search); + let nextUrl = urlParams.get('nextUrl'); + if (!nextUrl || nextUrl.toLowerCase().includes('//')) { + nextUrl = encodeURIComponent('/'); + } else { + nextUrl = encodeURIComponent(nextUrl); + const hash = window.location.hash || ''; + nextUrl += hash; + } + return `?nextUrl=${nextUrl}`; +} + export function LoginPage(props: LoginPageDeps) { const [username, setUsername] = React.useState(''); const [password, setPassword] = React.useState(''); diff --git a/public/utils/login-utils.tsx b/public/utils/login-utils.tsx index 97cfe8175..e66080c67 100644 --- a/public/utils/login-utils.tsx +++ b/public/utils/login-utils.tsx @@ -26,16 +26,3 @@ export async function validateCurrentPassword( password: currentPassword, }); } - -export function extractNextUrlFromWindowLocation(): string { - const urlParams = new URLSearchParams(window.location.search); - let nextUrl = urlParams.get('nextUrl'); - if (!nextUrl || nextUrl.toLowerCase().includes('//')) { - nextUrl = encodeURIComponent('/'); - } else { - nextUrl = encodeURIComponent(nextUrl); - const hash = window.location.hash || ''; - nextUrl += hash; - } - return `?nextUrl=${nextUrl}`; -}