Возможный необработанный отказ от обещания (id: 0): ReferenceError: Не удается найти переменную TextInputEmail - PullRequest
0 голосов
/ 30 января 2020

enter image description here

import React,{Component} from 'react';
import {View,Text,Image,ImageBackground,
         TextInput,TouchableOpacity,AsyncStorage,
        ActivityIndicator,StatusBar,StyleSheet} from 'react-native';
import {createStackNavigator} from 'react-navigation-stack' ;
import {createAppContainer,createSwitchNavigator} from 'react-navigation';
import AppContainer from '../App'
import Forgot from '../Screens/Forgot' ;
 class Home extends Component {
  constructor(props) {
    super(props);
    this.state = {
      TextInputEmail: '',
      TextInputPassword: '',
    };
  }

   CheckTextInput = async() =>
   {
     if (this.state.TextInputEmail != '')
         {
            if(this.state.TextInputPassword != '')
           {
              // if(userInfo.TextInputEmail === this.state.TextInputEmail &&
            // userInfo.TextInputPassword===this.state.TextInputPassword)

              fetch('http://104.197.28.169:3000/auth/login?', {
                method: 'POST',
                body: JSON.stringify({
                  "email": TextInputEmail,
                  "password": TextInputPassword
                }),
                })
                .then((response) => response.json())
                .then(() => {
                  this.props.navigation.navigate('drawernavi')
                    console.log('response object:',responseJson)
                })
                .catch((error) => {
                  console.error(error);
                  throw error;
                });
              //  await AsyncStorage.setItem('isLoggedIn','1');
              // this.props.navigation.navigate('drawernavi')
              //this.userLogin()
               // alert('Legged in')
              // this.userLogin();
          }
           else
            alert('Please Enter Password');
        } else
        alert('Please Enter Email & Password');
   }



  render(){
    return(

      <View>
       <ImageBackground style={{width:'100%',height:'100%'}}
        source={require('../images/login-screen.png')}>
        <View style={{flex:.8,alignItems:'center',justifyContent:'center',marginTop:20}}>


        <View style={styles.imageView}>
<Image style={styles.logoImg}
source = {require('../images/core-logo.png')}
></Image>
</View>


          <TextInput style={{fontSize:15,borderWidth:1,borderRadius:20,paddingLeft:15,width:300,
          borderColor:'black',height:40,marginTop:40}} 
          keyboardType='email-address'
          maxLength={32}
          placeholder='Email' placeholderTextColor='#a8a8a8'
          onChangeText={TextInputEmail => this.setState({ TextInputEmail })}
          value= {this.state.TextInputEmail}
          underlineColorAndroid="transparent">
          </TextInput>

          <TextInput style={{width:300,fontSize:15,borderWidth:1,borderRadius:20,paddingLeft:15,
          borderColor:'black',marginTop:20,height:40}}
          secureTextEntry={true}
          maxLength={14}

           placeholder='Password' placeholderTextColor='#a8a8a8'
           onChangeText={TextInputPassword => this.setState({ TextInputPassword })}
           value= {this.state.TextInputPassword}
           underlineColorAndroid="transparent">
          </TextInput>

          <TouchableOpacity
          style={{width:300,marginTop:35,paddingTop:10,paddingBottom:10,backgroundColor:'#2F6995',
            borderRadius:20,borderWidth: 1,borderColor: '#fff'}}

            onPress={this.CheckTextInput}
           underlayColor='#fff'>
          <Text style={{color:'#fff',textAlign:'center', paddingLeft : 10, paddingRight : 10,fontSize:17}}>LOGIN</Text>


     </TouchableOpacity>
         <View style={{alignItems:'center',marginTop:30}}>
        <TouchableOpacity
         onPress={() => this.props.navigation.navigate('forgotstack')} >
         <Text style={{fontSize:12.5,color:'black',borderBottomWidth:1}}> Forgot Password ? </Text>
       </TouchableOpacity>
       </View>
       </View>

        </ImageBackground>
      </View>

    );
  }
}

Я создаю функциональность входа в систему. я получил эту ошибку, работая над этим. я новичок в этом. когда я пытался войти в систему, появляются желтые предупреждения, я получаю данные через node.js API. поэтому требуется, чтобы имя поля ввода в api и response было одинаковым или оно могло быть другим, или есть другой способ, пожалуйста, предложите исправить мой код, если он неправильный

Ответы [ 2 ]

0 голосов
/ 30 января 2020
     body: JSON.stringify({
                  "email": TextInputEmail,
                  "password": TextInputPassword
                }),
//Change it to
 body: JSON.stringify({
                  "email": this.state.TextInputEmail,
                  "password": this.state.TextInputPassword
                }),
0 голосов
/ 30 января 2020

Проблема if(userInfo.TextInputEmail === this.state.TextInputEmail) в этих условиях userInfo не определено, поэтому userInfo.TextInputEmail не определено.

проверьте один раз

...