title: Csrf token post in React Native
body: <p>I've made a website using Node and Express as a framework. Now we are shifting to a React Native Mobile Application. While making the login page I have made a post request as given below</p>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>import React, { Component } from 'react'
  import {
    View,
    TextInput,
    Text,
    Button,
    Alert,
  } from 'react-native';
  import styles from './styles'
  
  class Home extends Component {
    constructor(props){
      super(props)
      state = {email: "", password: ""}
    }
  
    checkLogin(){
      const { email, password } = this.state;
      if(email ==="admin" || password === "admin" || true){
          fetch('http://localhost:3021/user/signin', {
            method: 'POST',
            headers: {
              Accept: 'application/json',
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              email: email,
              password: password,
            }),
          })
          .then((response) =&gt; {
            console.log(response)
          })
          .catch((error) =&gt; {
            console.error(error);
          })
        }
        else{
        Alert.alert('Error', 'Email/Password mismatch', [{
          text: 'Okay',
        }])
      }
    }
  
    render(){
      const {heading, input, parent} = styles
  
      return (
        &lt;View style={parent}&gt;
          &lt;Text style={heading}&gt; Login into the Application &lt;/Text&gt;
          &lt;TextInput style={input} placeholder="Email" onChangeText={text =&gt; this.setState({email: text})} underlineColorAndroid='black'/&gt;
          &lt;TextInput style={input} secureTextEntry={true} placeholder="Password" onChangeText={text =&gt; this.setState({password: text})}  underlineColorAndroid='black'/&gt;
  
          &lt;Button title={"Login"} onPress = {() =&gt; this.checkLogin()} /&gt;
        &lt;/View&gt;
      );
    }
  
  }
  
  export default Home
  </code></pre>
  
  <p>When I sent this request, I got no response and checked it on Postman for the response and it was coming as an invalid csrf token and 403 error. Initially in my web app while logging in, the form consisted of a CSRF token which was passed as given below: </p>
  
  <pre><code>&lt;input type = "hidden" name="_csrf" value="{{ csrfToken }}"&gt;
  </code></pre>
  
  <p>How do I replicate this on the React Native App? I tried searching online, however, could not find any such method discussed. </p>