无论如何,Firebase都无法进行身份验证

时间:2019-07-14 16:00:23

标签: javascript firebase react-native firebase-authentication

enter image description here我正在尝试使用Firebase身份验证,并使其在catch情况下向我显示“身份验证失败”,否则向我显示“成功”,但即使在我遇到故障时,它也仅向我显示“身份验证失败”消息输入全新的电子邮件和密码。

  //the firebase code
  this.state={
        email: '',
        password: '',
        errorMessage: '',
    }
    const {email, password} = this.state;
    this.setState({errorMessage: 'success'});
    this.onButtonPress = () =>{
        firebase.auth().signInWithEmailAndPassword(email, password)
        .catch(() => {
            firebase.auth().createUserWithEmailAndPassword(email, 
    password)
            .catch(() => {
                this.setState({errorMessage: 'Failed to Authenticate'});
            });
        });
    }

    //I'm grabbing the email and password from the textInput and 
    assigning them to this.state.email and this.state.password

           <InputField
                fieldText={'Email:'}
                onChangeText={email => this.setState({email})}
                value={this.state.email}
                placeholder={'Please enter your email'} />

     // and the password is the same except for this.state.password and 
     setState

     //the component:
     <Text style={{fontSize: 20, color: 'red', alignSelf: 'center'}}> 
     {this.state.errorMessage}</Text>
        <Inline>
            <Button buttonText={'Log In'}
            onPress={this.onButtonPress}
            />

1 个答案:

答案 0 :(得分:0)

您在firebase.auth()。signInWithEmailAndPassword(电子邮件,密码)上具有.catch和.catch

也许是问题所在?应该是.then表示成功,.catch表示错误

如果您要打印实际问题,只需这样做

            .catch((e) => {
              console.log(e)
            });