diff --git a/spiffworkflow-frontend/src/helpers.tsx b/spiffworkflow-frontend/src/helpers.tsx index f102c3db..d2dc0d5f 100644 --- a/spiffworkflow-frontend/src/helpers.tsx +++ b/spiffworkflow-frontend/src/helpers.tsx @@ -140,6 +140,11 @@ export const truncateString = (text: string, len: number) => { return text; }; +export const pathFromFullUrl = (fullUrl: string) => { + const parsedURL = new URL(fullUrl); + return parsedURL.pathname; +}; + // Because of limitations in the way openapi defines parameters, we have to modify process models ids // which are basically paths to the models export const modifyProcessIdentifierForPathParam = (path: string) => { diff --git a/spiffworkflow-frontend/src/services/UserService.ts b/spiffworkflow-frontend/src/services/UserService.ts index d5066da9..a2a54fca 100644 --- a/spiffworkflow-frontend/src/services/UserService.ts +++ b/spiffworkflow-frontend/src/services/UserService.ts @@ -2,6 +2,7 @@ import jwt from 'jwt-decode'; import cookie from 'cookie'; import { BACKEND_BASE_URL } from '../config'; import { AuthenticationOption } from '../interfaces'; +import { pathFromFullUrl } from '../helpers'; // NOTE: this currently stores the jwt token in local storage // which is considered insecure. Server set cookies seem to be considered @@ -32,10 +33,14 @@ const getCurrentLocation = (queryParams: string = window.location.search) => { ); }; -const checkPathForTaskShowParams = () => { +const checkPathForTaskShowParams = ( + redirectUrl: string = window.location.pathname +) => { + const path = pathFromFullUrl(redirectUrl); + // expected url pattern: // /tasks/[process_instance_id]/[task_guid] - const pathSegments = window.location.pathname.match( + const pathSegments = path.match( /^\/tasks\/(\d+)\/([0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12})$/ ); if (pathSegments) { @@ -48,7 +53,7 @@ const doLogin = ( authenticationOption?: AuthenticationOption, redirectUrl?: string | null ) => { - const taskShowParams = checkPathForTaskShowParams(); + const taskShowParams = checkPathForTaskShowParams(redirectUrl || undefined); const loginParams = [`redirect_url=${redirectUrl || getCurrentLocation()}`]; if (taskShowParams) { loginParams.push(