title: How can I get the Cookies' `csrftoken` in `Axios.interceptors.request`'s config?
body: <p>How can I get the Cookies' <code>csrftoken</code> in <code>Axios.interceptors.request</code>'s config?</p>
  
  <pre><code>Axios.interceptors.request.use(
    config =&gt; {
  
      if (
        config.method === "post" ||
        config.method === "put" ||
        config.method === "delete"||
        config.method === "get"
      ) {
  
      }
  
  
      if (Cookies.get('token')!==undefined) {   
        config.headers['Authorization']= 'Token '+Cookies.get('token');
      }
      // there I try to get the `csrftoken` in the Cookies, but I can not get.
      if (Cookies.get('csrftoken')!==undefined) {   
  
        config.headers['x-csrftoken']= Cookies.get('csrftoken');  // 'CSRFToken'
      }
  
      return config;
    },
    error =&gt; {  
      return Promise.reject(error.data.error.message);
    }
  );
  </code></pre>
  
  <p>In the <code>Axios.interceptors.request</code>'s config I can not get Cookies's <code>csrftoken</code>: <code>Cookies.get('csrftoken')</code>.</p>
  
  <p>my AxiosConfig code is bellow:</p>
  
  <pre><code>AxiosConfig:{
      baseURL: 'http://10.10.10.105:8001/',
  
      responseType: "json",
      withCredentials: true,  // there will send the Cookie (with it there are: sessionid, csrftoken)
  
      xsrfCookieName: 'csrftoken',  // default: XSRF-TOKEN
      xsrfHeaderName: 'x-csrftoken',   // default: X-XSRF-TOKEN
      headers: {
        "Content-Type": "application/json;charset=utf-8"
      }
    }
  </code></pre>
  
  <hr>
  
  <p><strong>edit-1</strong></p>
  
  <p>There is the <code>csrftoken</code> in the Cookie.</p>
  
  <p><a href="https://i.stack.imgur.com/buSZJ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/buSZJ.jpg" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>edit-2</strong></p>
  
  <p>And in the cookie, there is no <code>csrftoken</code> too.</p>
  
  <p><a href="https://i.stack.imgur.com/CK5zt.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/CK5zt.jpg" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>edit-3</strong></p>
  
  <p>if I get the <code>document.cookie</code> in console, I will get the <code>""</code>:
  ```</p>
  
  <blockquote>
    <p>document.cookie<br>
    &lt; ""
    ```</p>
  </blockquote>
  
  <hr>
  
  <p><strong>edit-4</strong></p>
  
  <p>in my Django backend, the <code>settings.py</code>:</p>
  
  <p>INSTALLED_APPS:</p>
  
  <pre><code>...
  'corsheaders', 
  
  'rest_framework',
  'rest_framework.authtoken',
  'rest_framework_docs',   
  'rest_auth',
  'allauth',
  'allauth.account',
  'allauth.socialaccount',
  'rest_auth.registration',
  ...
  </code></pre>
  
  <p>I am not sure whether the <code>rest_auth</code> and <code>allauth</code> will affect the <code>csrftoken</code>.</p>