accounts-frontend/packages/app/containers/AuthFlowRouteContents.tsx
ErickSkrauch af59cc033f
Extract device code into a separate view.
Convert more components from class components to functional.
Fix invalid finish state when client was auto approved
2024-12-14 13:16:29 +01:00

35 lines
1.1 KiB
TypeScript

import React, { FC, ReactElement, ComponentType, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { useIsMounted } from 'app/hooks';
import authFlow from 'app/services/authFlow';
interface Props extends RouteComponentProps {
component: ComponentType<RouteComponentProps>;
}
const AuthFlowRouteContents: FC<Props> = ({ component: WantedComponent, location, match, history }) => {
const isMounted = useIsMounted();
const [component, setComponent] = useState<ReactElement | null>(null);
useEffect(() => {
authFlow.handleRequest(
{
path: location.pathname,
params: match.params,
query: new URLSearchParams(location.search),
},
history.push,
() => {
if (isMounted()) {
setComponent(<WantedComponent history={history} location={location} match={match} />);
}
},
);
}, [location.pathname, location.search]);
return component;
};
export default AuthFlowRouteContents;