Skip to content

Commit

Permalink
Move function to login-page
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Aug 22, 2023
1 parent e5479f3 commit 19368da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 14 additions & 1 deletion public/apps/login/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Check warning on line 70 in public/apps/login/login-page.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/login/login-page.tsx#L70

Added line #L70 was not covered by tests
const hash = window.location.hash || '';
nextUrl += hash;

Check warning on line 72 in public/apps/login/login-page.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/login/login-page.tsx#L72

Added line #L72 was not covered by tests
}
return `?nextUrl=${nextUrl}`;
}

export function LoginPage(props: LoginPageDeps) {
const [username, setUsername] = React.useState('');
const [password, setPassword] = React.useState('');
Expand Down
13 changes: 0 additions & 13 deletions public/utils/login-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

0 comments on commit 19368da

Please sign in to comment.