title: React Native Fetch Request Fails Without CSRF Token
body: <p>I've been developing a mobile complement to my web application built with Rails. Using Fetch API, I keep getting the notice "Can't verify CSRF token authenticity".</p>
  
  <pre><code>export const login = (user) =&gt; {
    fetch('http://localhost:3000/api/session', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({user})
    })
    // promise handling
  }
  </code></pre>
  
  <p><strong>Edit:</strong> Managed to get it to work but I still don't really understand why. If anyone has the same problem, this is how I resolved it. I managed to get the form_authenticity_token from my rails application and saved it as a variable that I then passed to the function. Haven't tested removing the credentials key.</p>
  
  <pre><code>export const login = (user, token) =&gt; {
    return fetch('http://localhost:3000/api/session', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ user, authenticity_token: token })
    })
  </code></pre>