2024-12-14 13:16:29 +01:00
|
|
|
import React, { FC, ReactElement, ComponentType, useEffect, useState } from 'react';
|
|
|
|
import { RouteComponentProps } from 'react-router-dom';
|
2017-05-25 22:11:57 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
import { useIsMounted } from 'app/hooks';
|
2019-12-07 21:02:00 +02:00
|
|
|
import authFlow from 'app/services/authFlow';
|
2017-05-25 22:11:57 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
interface Props extends RouteComponentProps {
|
|
|
|
component: ComponentType<RouteComponentProps>;
|
2019-12-10 09:47:32 +02:00
|
|
|
}
|
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
const AuthFlowRouteContents: FC<Props> = ({ component: WantedComponent, location, match, history }) => {
|
|
|
|
const isMounted = useIsMounted();
|
|
|
|
const [component, setComponent] = useState<ReactElement | null>(null);
|
2020-05-24 02:08:24 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
useEffect(() => {
|
2020-05-24 02:08:24 +03:00
|
|
|
authFlow.handleRequest(
|
|
|
|
{
|
2024-12-14 13:16:29 +01:00
|
|
|
path: location.pathname,
|
|
|
|
params: match.params,
|
|
|
|
query: new URLSearchParams(location.search),
|
|
|
|
},
|
|
|
|
history.push,
|
|
|
|
() => {
|
|
|
|
if (isMounted()) {
|
|
|
|
setComponent(<WantedComponent history={history} location={location} match={match} />);
|
|
|
|
}
|
2020-05-24 02:08:24 +03:00
|
|
|
},
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
}, [location.pathname, location.search]);
|
2020-05-24 02:08:24 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
return component;
|
|
|
|
};
|
2020-05-24 02:08:24 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export default AuthFlowRouteContents;
|