diff --git a/src/modules/login/LoginCallback.tsx b/src/modules/login/LoginCallback.tsx
index 497578d..c58c671 100644
--- a/src/modules/login/LoginCallback.tsx
+++ b/src/modules/login/LoginCallback.tsx
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
-import { RouteComponentProps } from '@reach/router';
+import { navigate, RouteComponentProps } from '@reach/router';
import { useAuth } from 'src/services/auth';
import { showToast, ToastType } from 'src/common/util/show-toast';
@@ -7,19 +7,25 @@ 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 { logIn } = useAuth();
useEffect(() => {
- const res = logIn();
+ if (state) {
+ const res = logIn(state);
- // @ts-ignore
- if (res.ok) {
- showToast('Logged in');
- } else {
- showToast('Something went wrong', ToastType.Error);
- // navigate('/login');
+ // @ts-ignore
+ if (res.ok) {
+ showToast('Logged in');
+ } else {
+ showToast('Something went wrong', ToastType.Error);
+ navigate('/login');
+ }
}
- }, [logIn]);
+ }, [logIn, state]);
return (
diff --git a/src/services/auth/hooks/use-auth.ts b/src/services/auth/hooks/use-auth.ts
index 6630032..38d017d 100644
--- a/src/services/auth/hooks/use-auth.ts
+++ b/src/services/auth/hooks/use-auth.ts
@@ -6,9 +6,12 @@ export function useAuth() {
const dispatch = useDispatch();
const auth = useSelector(getAuth);
- const logIn = useCallback(() => {
- return dispatch(signIn());
- }, [dispatch]);
+ const logIn = useCallback(
+ (state) => {
+ return dispatch(signIn(state));
+ },
+ [dispatch],
+ );
const logOut = useCallback(() => {
return dispatch(signOut());
diff --git a/src/services/auth/redux/actions.ts b/src/services/auth/redux/actions.ts
index 0634689..770bd8e 100644
--- a/src/services/auth/redux/actions.ts
+++ b/src/services/auth/redux/actions.ts
@@ -15,11 +15,14 @@ const signOutAction = (): SuccessAction => ({
payload: null,
});
-export const signIn = () =>
+export const signIn = (state: string) =>
createApiAction(
{
path: '/hydra/callback',
method: 'GET',
+ headers: {
+ state,
+ },
},
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
);