diff --git a/src/components/AuthUser/AuthUser.tsx b/src/components/AuthUser/AuthUser.tsx index 51621049d7d74beaf16d4e6a60f0933d454b2bdd..144b5460cfea22a5f50a0b2d7205a6618a67d0bf 100644 --- a/src/components/AuthUser/AuthUser.tsx +++ b/src/components/AuthUser/AuthUser.tsx @@ -3,12 +3,18 @@ import axios from 'axios'; import Container from '@material-ui/core/Container'; 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 = () => { + configDjangoCookieName(); useEffect(() => { axios .get('api/web/csrf') .then((response) => { - // Check this https://stackoverflow.com/questions/39254562/csrf-with-django-reactredux-using-axios axios.defaults.headers.common['X-CSRFTOKEN'] = response.data.token; }) .catch((error) => error); diff --git a/src/components/AuthUser/SignInForm/SignInForm.tsx b/src/components/AuthUser/SignInForm/SignInForm.tsx index bdb8ad4c499af5173b5d9de5aedb4e55817093e8..1de3d63935aab54bfdae5c3df2cff294b3577a29 100644 --- a/src/components/AuthUser/SignInForm/SignInForm.tsx +++ b/src/components/AuthUser/SignInForm/SignInForm.tsx @@ -41,16 +41,18 @@ export const SignInForm: FC = () => { }); const onSubmit: SubmitHandler<FormData> = (values: FormData) => { - axios - .post('/api/web/login', { - values, - }) - .then((response) => { - // Handle server reponse - }) - .catch((error) => { - // Handle error - }); + axios.post( + '/api/web/login', + { + username: values.email, + password: values.password, + }, + { + headers: { + 'Content-Type': 'application/json', + }, + }, + ); }; const intl = useIntl(); const classes = useStyles();