2021-10-19 13:08:25 +02:00
|
|
|
import SimpleAuth from '../SimpleAuth/SimpleAuth';
|
|
|
|
import AuthenticationCustomComponent from '../authentication-custom-component';
|
|
|
|
import PasswordAuth from '../PasswordAuth/PasswordAuth';
|
|
|
|
import HostedAuth from '../HostedAuth/HostedAuth';
|
2022-02-10 17:04:10 +01:00
|
|
|
import DemoAuth from '../DemoAuth/DemoAuth';
|
2021-10-19 13:08:25 +02:00
|
|
|
import {
|
|
|
|
SIMPLE_TYPE,
|
|
|
|
DEMO_TYPE,
|
|
|
|
PASSWORD_TYPE,
|
|
|
|
HOSTED_TYPE,
|
|
|
|
} from '../../../constants/authTypes';
|
|
|
|
import SecondaryLoginActions from '../common/SecondaryLoginActions/SecondaryLoginActions';
|
|
|
|
import useQueryParams from '../../../hooks/useQueryParams';
|
|
|
|
import ConditionallyRender from '../../common/ConditionallyRender';
|
|
|
|
import { Alert } from '@material-ui/lab';
|
2022-02-10 17:04:10 +01:00
|
|
|
import { useAuthDetails } from '../../../hooks/api/getters/useAuth/useAuthDetails';
|
2021-10-19 13:08:25 +02:00
|
|
|
|
2022-02-21 14:05:11 +01:00
|
|
|
interface IAuthenticationProps {
|
|
|
|
redirect: string;
|
|
|
|
}
|
|
|
|
const Authentication = ({ redirect }: IAuthenticationProps) => {
|
2022-02-10 17:04:10 +01:00
|
|
|
const { authDetails } = useAuthDetails();
|
2021-10-19 13:08:25 +02:00
|
|
|
const params = useQueryParams();
|
|
|
|
|
|
|
|
const error = params.get('errorMsg');
|
|
|
|
if (!authDetails) return null;
|
|
|
|
|
|
|
|
let content;
|
|
|
|
if (authDetails.type === PASSWORD_TYPE) {
|
|
|
|
content = (
|
|
|
|
<>
|
2022-02-21 14:05:11 +01:00
|
|
|
<PasswordAuth authDetails={authDetails} redirect={redirect} />
|
2021-10-19 13:08:25 +02:00
|
|
|
<ConditionallyRender
|
2022-01-26 13:28:51 +01:00
|
|
|
condition={!authDetails.defaultHidden}
|
2021-10-19 13:08:25 +02:00
|
|
|
show={<SecondaryLoginActions />}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else if (authDetails.type === SIMPLE_TYPE) {
|
2022-02-21 14:05:11 +01:00
|
|
|
content = <SimpleAuth authDetails={authDetails} redirect={redirect} />;
|
2021-10-19 13:08:25 +02:00
|
|
|
} else if (authDetails.type === DEMO_TYPE) {
|
2022-02-21 14:05:11 +01:00
|
|
|
content = <DemoAuth authDetails={authDetails} redirect={redirect} />;
|
2021-10-19 13:08:25 +02:00
|
|
|
} else if (authDetails.type === HOSTED_TYPE) {
|
|
|
|
content = (
|
|
|
|
<>
|
2022-02-21 14:05:11 +01:00
|
|
|
<HostedAuth authDetails={authDetails} redirect={redirect} />
|
2021-10-19 13:08:25 +02:00
|
|
|
<ConditionallyRender
|
2022-01-26 13:28:51 +01:00
|
|
|
condition={!authDetails.defaultHidden}
|
2021-10-19 13:08:25 +02:00
|
|
|
show={<SecondaryLoginActions />}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
2022-02-21 14:05:11 +01:00
|
|
|
content = (
|
|
|
|
<AuthenticationCustomComponent
|
|
|
|
authDetails={authDetails}
|
|
|
|
redirect={redirect}
|
|
|
|
/>
|
|
|
|
);
|
2021-10-19 13:08:25 +02:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div style={{ maxWidth: '350px' }}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(error)}
|
|
|
|
show={<Alert severity="error">{error}</Alert>}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{content}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Authentication;
|