1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

feat: add redirect to all auth components

This commit is contained in:
Youssef 2022-02-21 14:05:11 +01:00
parent bcbfd3e38c
commit 622c97a99f
6 changed files with 25 additions and 18 deletions

View File

@ -15,7 +15,10 @@ import ConditionallyRender from '../../common/ConditionallyRender';
import { Alert } from '@material-ui/lab';
import { useAuthDetails } from '../../../hooks/api/getters/useAuth/useAuthDetails';
const Authentication = () => {
interface IAuthenticationProps {
redirect: string;
}
const Authentication = ({ redirect }: IAuthenticationProps) => {
const { authDetails } = useAuthDetails();
const params = useQueryParams();
@ -26,7 +29,7 @@ const Authentication = () => {
if (authDetails.type === PASSWORD_TYPE) {
content = (
<>
<PasswordAuth authDetails={authDetails} />
<PasswordAuth authDetails={authDetails} redirect={redirect} />
<ConditionallyRender
condition={!authDetails.defaultHidden}
show={<SecondaryLoginActions />}
@ -34,13 +37,13 @@ const Authentication = () => {
</>
);
} else if (authDetails.type === SIMPLE_TYPE) {
content = <SimpleAuth authDetails={authDetails} />;
content = <SimpleAuth authDetails={authDetails} redirect={redirect} />;
} else if (authDetails.type === DEMO_TYPE) {
content = <DemoAuth authDetails={authDetails} />;
content = <DemoAuth authDetails={authDetails} redirect={redirect} />;
} else if (authDetails.type === HOSTED_TYPE) {
content = (
<>
<HostedAuth authDetails={authDetails} />
<HostedAuth authDetails={authDetails} redirect={redirect} />
<ConditionallyRender
condition={!authDetails.defaultHidden}
show={<SecondaryLoginActions />}
@ -48,7 +51,12 @@ const Authentication = () => {
</>
);
} else {
content = <AuthenticationCustomComponent authDetails={authDetails} />;
content = (
<AuthenticationCustomComponent
authDetails={authDetails}
redirect={redirect}
/>
);
}
return (
<>

View File

@ -9,7 +9,7 @@ import { useAuthApi } from '../../../hooks/api/actions/useAuthApi/useAuthApi';
import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
import useToast from '../../../hooks/useToast';
const DemoAuth = ({ authDetails }) => {
const DemoAuth = ({ authDetails, redirect }) => {
const [email, setEmail] = useState('');
const history = useHistory();
const { refetchUser } = useAuthUser();
@ -22,7 +22,7 @@ const DemoAuth = ({ authDetails }) => {
try {
await emailAuth(authDetails.path, email);
refetchUser();
history.push(`/`);
history.push(redirect);
} catch (e) {
setToastApiError(e.toString());
}

View File

@ -18,7 +18,7 @@ import {
LOGIN_PASSWORD_ID,
} from '../../../testIds';
const HostedAuth = ({ authDetails }) => {
const HostedAuth = ({ authDetails, redirect }) => {
const commonStyles = useCommonStyles();
const styles = useStyles();
const { refetchUser } = useAuthUser();
@ -55,7 +55,7 @@ const HostedAuth = ({ authDetails }) => {
try {
await passwordAuth(authDetails.path, username, password);
refetchUser();
history.push(`/`);
history.push(redirect);
} catch (error) {
if (error.statusCode === 404 || error.statusCode === 400) {
setErrors(prev => ({

View File

@ -17,11 +17,9 @@ const Login = () => {
const resetPassword = query.get('reset') === 'true';
const redirect = query.get('redirect') || '/features';
const history = useHistory();
console.log(redirect);
if (user) {
console.log(redirect);
history.push(redirect);
history.replace(redirect);
}
return (
@ -40,7 +38,7 @@ const Login = () => {
condition={resetPassword}
show={<ResetPasswordSuccess />}
/>
<Authentication />
<Authentication redirect={redirect} />
</div>
</StandaloneLayout>
);

View File

@ -19,7 +19,7 @@ import PasswordField from '../../common/PasswordField/PasswordField';
import { useAuthApi } from '../../../hooks/api/actions/useAuthApi/useAuthApi';
import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
const PasswordAuth = ({ authDetails }) => {
const PasswordAuth = ({ authDetails, redirect }) => {
const commonStyles = useCommonStyles();
const styles = useStyles();
const history = useHistory();
@ -56,7 +56,8 @@ const PasswordAuth = ({ authDetails }) => {
try {
await passwordAuth(authDetails.path, username, password);
refetchUser();
history.push(`/`);
console.log('hio')
history.push(redirect);
} catch (error) {
if (error.statusCode === 404 || error.statusCode === 400) {
setErrors(prev => ({

View File

@ -8,7 +8,7 @@ import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
import { LOGIN_BUTTON, LOGIN_EMAIL_ID } from '../../../testIds';
import useToast from '../../../hooks/useToast';
const SimpleAuth = ({ authDetails }) => {
const SimpleAuth = ({ authDetails, redirect }) => {
const [email, setEmail] = useState('');
const { refetchUser } = useAuthUser();
const { emailAuth } = useAuthApi();
@ -21,7 +21,7 @@ const SimpleAuth = ({ authDetails }) => {
try {
await emailAuth(authDetails.path, email);
refetchUser();
history.push(`/`);
history.push(redirect);
} catch (e) {
setToastApiError(e.toString());
}