From 88fff73cc01cd85e2684ef6eb420a470db3cb514 Mon Sep 17 00:00:00 2001 From: Valentino Kozinec Date: Wed, 19 Jan 2022 12:01:17 +0100 Subject: [PATCH] Params fix --- src/modules/login/LoginCallback.tsx | 11 +++++------ src/services/auth/hooks/use-auth.ts | 4 ++-- src/services/auth/redux/actions.ts | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/modules/login/LoginCallback.tsx b/src/modules/login/LoginCallback.tsx index c58c671..9925f2e 100644 --- a/src/modules/login/LoginCallback.tsx +++ b/src/modules/login/LoginCallback.tsx @@ -8,15 +8,14 @@ type LoginCallbackProps = RouteComponentProps; // eslint-disable-next-line @typescript-eslint/no-unused-vars export function LoginCallback(_: LoginCallbackProps) { const currentURL = window.location.href; - const urlParams = new URLSearchParams(currentURL); - const state = urlParams.get('state'); + const indexOfQuestionMark = currentURL.indexOf('?'); + const params = currentURL.slice(indexOfQuestionMark); const { logIn } = useAuth(); useEffect(() => { - if (state) { - const res = logIn(state); - + if (params) { + const res = logIn(params); // @ts-ignore if (res.ok) { showToast('Logged in'); @@ -25,7 +24,7 @@ export function LoginCallback(_: LoginCallbackProps) { navigate('/login'); } } - }, [logIn, state]); + }, [logIn, params]); return (
diff --git a/src/services/auth/hooks/use-auth.ts b/src/services/auth/hooks/use-auth.ts index 38d017d..5d7e37e 100644 --- a/src/services/auth/hooks/use-auth.ts +++ b/src/services/auth/hooks/use-auth.ts @@ -7,8 +7,8 @@ export function useAuth() { const auth = useSelector(getAuth); const logIn = useCallback( - (state) => { - return dispatch(signIn(state)); + (params) => { + return dispatch(signIn(params)); }, [dispatch], ); diff --git a/src/services/auth/redux/actions.ts b/src/services/auth/redux/actions.ts index 7a27650..9fb3bca 100644 --- a/src/services/auth/redux/actions.ts +++ b/src/services/auth/redux/actions.ts @@ -15,10 +15,10 @@ const signOutAction = (): SuccessAction => ({ payload: null, }); -export const signIn = (state: string) => +export const signIn = (params: string) => createApiAction( { - path: `/hydra/callback?state=${state}`, + path: `/hydra/callback${params}`, method: 'GET', }, [AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],