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

Merge branch 'api-login' into 'master'

Set csrf name for django

See merge request !20
parents f29da43a f4f2cbb1
No related branches found
No related tags found
1 merge request!20Set csrf name for django
Pipeline #11673 failed
...@@ -3,12 +3,18 @@ import axios from 'axios'; ...@@ -3,12 +3,18 @@ import axios from 'axios';
import Container from '@material-ui/core/Container'; import Container from '@material-ui/core/Container';
import { SignInForm } from './SignInForm/SignInForm'; import { SignInForm } from './SignInForm/SignInForm';
const configDjangoCookieName = (): void => {
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN';
axios.defaults.xsrfCookieName = 'csrftoken';
axios.defaults.withCredentials = true;
};
export const AuthUser: FC = () => { export const AuthUser: FC = () => {
configDjangoCookieName();
useEffect(() => { useEffect(() => {
axios axios
.get('api/web/csrf') .get('api/web/csrf')
.then((response) => { .then((response) => {
// Check this https://stackoverflow.com/questions/39254562/csrf-with-django-reactredux-using-axios
axios.defaults.headers.common['X-CSRFTOKEN'] = response.data.token; axios.defaults.headers.common['X-CSRFTOKEN'] = response.data.token;
}) })
.catch((error) => error); .catch((error) => error);
......
...@@ -41,16 +41,18 @@ export const SignInForm: FC = () => { ...@@ -41,16 +41,18 @@ export const SignInForm: FC = () => {
}); });
const onSubmit: SubmitHandler<FormData> = (values: FormData) => { const onSubmit: SubmitHandler<FormData> = (values: FormData) => {
axios axios.post(
.post('/api/web/login', { '/api/web/login',
values, {
}) username: values.email,
.then((response) => { password: values.password,
// Handle server reponse },
}) {
.catch((error) => { headers: {
// Handle error 'Content-Type': 'application/json',
}); },
},
);
}; };
const intl = useIntl(); const intl = useIntl();
const classes = useStyles(); const classes = useStyles();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment