DEV Community

Discussion on: FullStack React & Django Authentication : Django REST ,TypeScript, Axios, Redux & React Router

Collapse
 
michaeldbrant profile image
Michael Brant

Thanks for the guide! Is anyone else getting a “CSRF cookie not set” error? I tried putting @csrf_exempt as a decorator above the create method in the RegistrationViewSet but that didn’t fix it.

Collapse
 
koladev profile image
Mangabo Kolawole

Hey Michael!

What's your CORS configuration? And are you using React?

Collapse
 
michaeldbrant profile image
Michael Brant

Hey! Yup, I’m using React, testing in the browser and in Postman. I’m running on port 8000 so I have :
CORS_ALLOWED_ORIGINS = [“127.0.0.1:8000”,
localhost:8000”]

CORS_ALLOW_HEADERS = [‘Accept’, ‘Accept-Language’, ‘Authorization’, ‘Content-Type’]

CORS_ALLOW_METHODS = [‘GET’, ‘POST’, ‘PUT’]

Collapse
 
zvolsky profile image
Zvolský

With Django/Vue/Axios I have such something in Axios settings:
axios.defaults.withCredentials = true
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
axios.defaults.xsrfCookieName = "csrftoken"