Skip to content
Snippets Groups Projects
Commit 3963f9e8 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Merge branch 'hide_password' into 'master'

is_authenticated, hide password and move styles

See merge request !39
parents 874941ea 80e069d2
No related branches found
No related tags found
1 merge request!39is_authenticated, hide password and move styles
Pipeline #11883 passed
import React, { FC } from 'react';
import axios from 'axios';
import { SubmitHandler, useForm } from 'react-hook-form';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import { Button } from '@material-ui/core';
import { InputField } from 'components/AuthUser/SignInForm/InputField/InputField';
import { useHistory } from 'react-router-dom';
import { AuthRoutes } from 'components/api/routes';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(0),
},
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1),
},
submit: {
margin: theme.spacing(3, 0, 2),
},
}),
);
import { useStyles } from './useStyles';
export const SignInForm: FC = () => {
const history = useHistory();
......@@ -37,7 +20,7 @@ export const SignInForm: FC = () => {
password: '',
};
const { control, errors, handleSubmit } = useForm<FormData>({
const { control, errors, setError, handleSubmit } = useForm<FormData>({
defaultValues,
});
......@@ -55,8 +38,19 @@ export const SignInForm: FC = () => {
},
},
)
.then(() => {
history.replace(AuthRoutes.dashboard);
.then((response) => {
if (response.data.status === 'fail') {
setError('email', {
type: 'server',
message: 'Something went wrong with email',
});
setError('password', {
type: 'server',
message: 'Something went wrong with password',
});
} else if (response.data.status === 'success') {
history.replace(AuthRoutes.dashboard);
}
});
};
......
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
export const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(0),
},
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1),
},
submit: {
margin: theme.spacing(3, 0, 2),
},
}),
);
......@@ -25,12 +25,10 @@ export const PrivateRoute = ({
useEffect(() => {
const fetch = async (): Promise<unknown> => {
const result = await axios('/api/web/login/is_authenticated');
// FIX: Remove negation and use true server data
setAuth(!result.data.is_authenticated);
setAuth(result.data.is_authenticated);
setLoading(true);
return null;
};
fetch();
}, []);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment