在Firebase中存储值并在React Native中导航

时间:2019-05-14 05:05:25

标签: firebase react-native

我有一个登录表单,填写此表单时,我希望将值存储在DB中,然后它将导航至确认页面。 问题是存储了空白值

PS:在没有DB插入功能的情况下,通过传递值的导航工作正常。

userLogin(email, password) {
  firebase.database().ref('users/').set({
    userEmail: email,
    userPass: password,
  }).catch((error)=>{
      console.log('error ' , error)
    });
}



           <Button
          title="Go to Details"
          onPress = {this.userLogin(this.state.email, this.state.password),
            this.props.navigation.navigate('Details', {
          email: this.state.email, 
          password: this.state.password,
          title: "Details Screen",
           })

          }
        />

1 个答案:

答案 0 :(得分:0)

  1. 使用Firebase身份验证处理注册和登录流程,Firebase将存储用户的身份验证详细信息。

userLogin = (email, password) =>{
        this.setState({
            loading:true
        })
        try {
            if(this.state.password.length >= 6){
                firebase.auth().signInWithEmailAndPassword(email,password).then(response =>{
                    this.props.navigation.navigate('Details');
                }).catch(error => {
                    alert("Email or password is incorrect");
                    this.setState({
                        loading: false
                    })
                })
            }else{
                alert("Password must be more than 6 characters")
                this.setState({
                    loading: false
                })
                return;
            }
        } catch (error) {
            console.log(error.toString())
        }
    }
    
    
    <Button title="Go to Details" onPress={()=>this. userLogin(this.state.email, this.state.password)} />

相关问题