Firebase Authentication FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred

后端 未结 17 1679
感情败类
感情败类 2020-12-06 04:55

I\'m creating an authentication workflow for my android app. I\'m allowing users to sign in with username/password and various OAuth providers. I\'m validating emails and pa

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 05:21

    If you do this check in form onSumbit handler, you need to preventDefault before sending a request.

    This is a snippet (React) that works:

    class LoginComponent extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                email: '',
                password: '',
            };
            this.login = this.login.bind(this);
            this.handleLoginChange = this.handleLoginChange.bind(this);
            this.handlePasswordChange = this.handlePasswordChange.bind(this);
        }
    
        handleLoginChange(event) {
            this.setState({
                email: event.target.value,
                password: this.state.password,
            });
        }
    
        handlePasswordChange(event) {
            this.setState({
                email: this.state.email,
                password: event.target.value,
            });
        }
    
        login(event) {
            event.preventDefault();
            firebase.auth()
                .signInWithEmailAndPassword(this.state.email, this.state.password)
                .then(function(user) {
                          window.alert('OK' + user);
                      },
                      function(error) {
                          window.alert('ERR' + error);
                      });
        }
    
        render() {
            return (
                


    ) } }

提交回复
热议问题