mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
4167a60588
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome to the frontend as well. ![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65) Added a few `biome-ignore` to speed up the process but we may want to check and fix them in the future.
92 lines
2.9 KiB
TypeScript
92 lines
2.9 KiB
TypeScript
import SimpleAuth from '../SimpleAuth/SimpleAuth';
|
|
import { AuthenticationCustomComponent } from 'component/user/AuthenticationCustomComponent';
|
|
import PasswordAuth from '../PasswordAuth';
|
|
import HostedAuth from '../HostedAuth';
|
|
import DemoAuth from '../DemoAuth/DemoAuth';
|
|
import {
|
|
SIMPLE_TYPE,
|
|
DEMO_TYPE,
|
|
PASSWORD_TYPE,
|
|
HOSTED_TYPE,
|
|
} from 'constants/authTypes';
|
|
import SecondaryLoginActions from '../common/SecondaryLoginActions';
|
|
import useQueryParams from 'hooks/useQueryParams';
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
import { Alert } from '@mui/material';
|
|
import { useAuthDetails } from 'hooks/api/getters/useAuth/useAuthDetails';
|
|
import { AUTH_PAGE_ID } from 'utils/testIds';
|
|
import { useEffect } from 'react';
|
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
|
|
|
interface IAuthenticationProps {
|
|
redirect: string;
|
|
invited?: boolean;
|
|
}
|
|
|
|
const Authentication = ({
|
|
redirect,
|
|
invited = false,
|
|
}: IAuthenticationProps) => {
|
|
const { authDetails } = useAuthDetails();
|
|
const params = useQueryParams();
|
|
const error = params.get('errorMsg');
|
|
const { trackEvent } = usePlausibleTracker();
|
|
|
|
useEffect(() => {
|
|
if (invited) {
|
|
trackEvent('invite', {
|
|
props: {
|
|
eventType: 'user created',
|
|
},
|
|
});
|
|
}
|
|
}, [invited, trackEvent]);
|
|
|
|
if (!authDetails) {
|
|
return null;
|
|
}
|
|
|
|
let content;
|
|
if (authDetails.type === PASSWORD_TYPE) {
|
|
content = (
|
|
<>
|
|
<PasswordAuth authDetails={authDetails} redirect={redirect} />
|
|
<ConditionallyRender
|
|
condition={!authDetails.defaultHidden}
|
|
show={<SecondaryLoginActions />}
|
|
/>
|
|
</>
|
|
);
|
|
} else if (authDetails.type === SIMPLE_TYPE) {
|
|
content = <SimpleAuth authDetails={authDetails} redirect={redirect} />;
|
|
} else if (authDetails.type === DEMO_TYPE) {
|
|
content = <DemoAuth authDetails={authDetails} redirect={redirect} />;
|
|
} else if (authDetails.type === HOSTED_TYPE) {
|
|
content = (
|
|
<>
|
|
<HostedAuth authDetails={authDetails} redirect={redirect} />
|
|
<ConditionallyRender
|
|
condition={!authDetails.defaultHidden}
|
|
show={<SecondaryLoginActions />}
|
|
/>
|
|
</>
|
|
);
|
|
} else {
|
|
content = <AuthenticationCustomComponent authDetails={authDetails} />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div style={{ maxWidth: '350px' }} data-testid={AUTH_PAGE_ID}>
|
|
<ConditionallyRender
|
|
condition={Boolean(error)}
|
|
show={<Alert severity='error'>{error}</Alert>}
|
|
/>
|
|
</div>
|
|
{content}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Authentication;
|