title: Django and React: csrf cookie is not being set in request header
body: <p>To explain my situation, if I logged in from backend, csrf cookie is set in cookie tab, the problem occur in frontend, if i try to login from there, csrf cookie is not in request header (being undefined), some code provided:</p>
  <p>settings.py:</p>
  <pre><code>ALLOWED_HOSTS = ['*']
  ACCESS_CONTROL_ALLOW_ORIGIN = '*'
  CORS_ORIGIN_ALLOW_ALL = True
  CORS_ALLOW_CREDENTIALS = True
  ACCESS_CONTROL_ALLOW_CREDENTIALS = True
  ACCESS_CONTROL_ALLOW_METHODS = '*'
  ACCESS_CONTROL_ALLOW_HEADERS = '*'
  
  '''
  SESSION_COOKIE_SECURE = True
  '''
  CSRF_COOKIE_SAMESITE = 'None'
  SESSION_COOKIE_SAMESITE = 'None'
  
  
  CSRF_TRUSTED_ORIGINS = [ &quot;http://127.0.0.1:3000&quot;,'http://127.0.0.1:8000','http://localhost:3000']
  </code></pre>
  <p>setting SAMESITE protocol to anything else haven't made any change</p>
  <p>in views.py, we have login view (class based):</p>
  <pre><code>class LoginView(views.APIView):
      permission_classes = [AllowAny,]
      serializer_class = serializer.LoginSerializer
      def post(self,request):
          data = serializer.LoginSerializer(data=request.data)
          print(data.is_valid())
          if data.is_valid():
              email = data.data['email']
              password = data.data['password']
              auth = authenticate(username=email,password=password)
              if auth:
                  login(request,auth)
                  return HttpResponse(&quot;Success&quot;,status=200)
              else:
                  print(password == &quot;&quot;)
                  if email == &quot;&quot; and password ==&quot;&quot;:
                      return HttpResponse('Both email and password field are empty',status=400)
  
                  elif email == &quot;&quot;:
                      return HttpResponse('Email field is empty',status=400)
                  elif password == &quot;&quot;:
                      return HttpResponse('Passowrd field is empty',status = 400)
          else:
              return HttpResponse(&quot;Both email and password fields are empty&quot;,status=400)
  </code></pre>
  <p>in serializer.py, we got the login serializer:</p>
  <pre><code>class LoginSerializer(serializers.Serializer):
      email = serializers.CharField(required=False)
      password = serializers.CharField(required=False,allow_null=True,allow_blank=True)
  </code></pre>
  <p>in react (frontend side), here is how i am making a post request:</p>
  <pre><code>function Login(){
      const [login,setLogin] = useState({'email':'','password':''})
      const {email,password} = login
      const navigate = useNavigate()
  
      let handleChange = (e)=&gt;{
          setLogin(
              {
                  ...login,
                  [e.target.name]:e.target.value
              }
          )
  
      }
  
      
      let handleSubmit = (e)=&gt;{
          e.preventDefault()
          axios.post('http://127.0.0.1:8000/login/',login,{headers: {'Content-Type': 'application/json','X-CSRFToken':Cookies.get('csrftoken')}}).then(
              (res)=&gt;{
  
   
                      console.log(res)
                      console.log(Cookies.get('csrftoken')) //undefined here
  
              }
          ).catch((e)=&gt;{
      console.log(e)
              }
          })
  
      }
  }
  
  </code></pre>
  <p>this is part of the code btw ^.</p>
  <p>edit:
  I have a csrf view too, not sure how to use it:</p>
  <pre><code>class GetCSRFToken(views.APIView):
      permission_classes = [AllowAny, ]
  
      def get(self, request, format=None):
          return Response({ 'success': 'CSRF cookie set' })
  </code></pre>
  <p>any help is welcomed.</p>