Params fix
This commit is contained in:
parent
786217b753
commit
88fff73cc0
3 changed files with 9 additions and 10 deletions
|
@ -8,15 +8,14 @@ type LoginCallbackProps = RouteComponentProps;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export function LoginCallback(_: LoginCallbackProps) {
|
export function LoginCallback(_: LoginCallbackProps) {
|
||||||
const currentURL = window.location.href;
|
const currentURL = window.location.href;
|
||||||
const urlParams = new URLSearchParams(currentURL);
|
const indexOfQuestionMark = currentURL.indexOf('?');
|
||||||
const state = urlParams.get('state');
|
const params = currentURL.slice(indexOfQuestionMark);
|
||||||
|
|
||||||
const { logIn } = useAuth();
|
const { logIn } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state) {
|
if (params) {
|
||||||
const res = logIn(state);
|
const res = logIn(params);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
showToast('Logged in');
|
showToast('Logged in');
|
||||||
|
@ -25,7 +24,7 @@ export function LoginCallback(_: LoginCallbackProps) {
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [logIn, state]);
|
}, [logIn, params]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
||||||
|
|
|
@ -7,8 +7,8 @@ export function useAuth() {
|
||||||
const auth = useSelector(getAuth);
|
const auth = useSelector(getAuth);
|
||||||
|
|
||||||
const logIn = useCallback(
|
const logIn = useCallback(
|
||||||
(state) => {
|
(params) => {
|
||||||
return dispatch(signIn(state));
|
return dispatch(signIn(params));
|
||||||
},
|
},
|
||||||
[dispatch],
|
[dispatch],
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,10 +15,10 @@ const signOutAction = (): SuccessAction => ({
|
||||||
payload: null,
|
payload: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const signIn = (state: string) =>
|
export const signIn = (params: string) =>
|
||||||
createApiAction(
|
createApiAction(
|
||||||
{
|
{
|
||||||
path: `/hydra/callback?state=${state}`,
|
path: `/hydra/callback${params}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
|
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
|
||||||
|
|
Loading…
Reference in a new issue