【问题标题】:Cannot connect to Firebase authentication (nothing happen)无法连接到 Firebase 身份验证(没有任何反应)
【发布时间】:2017-11-07 04:33:48
【问题描述】:

我构建了一些身份验证应用程序,包括在 firebase 上输入用户名、密码。但是在我按下应用程序上的登录按钮后什么也没有发生。它只显示“身份验证失败”。

    class LoginForm extends Component {
      state = {
        email: '',password: '',error: '',loading: false
      };

      onButtonPress() {
        const { email, password } = this.state;
        this.setState({ error: '', loading: true });
        firebase.auth().signInWithEmailAndPassword(email, password)
          .then(this.onLoginSuccess.bind(this))
          .catch(() => {
            firebase.auth().createUserWithEmailAndPassword(email, password)
              .then(this.onLoginSuccess.bind(this))
              .catch(this.onLoginFail.bind(this));
          });
      }

      onLoginFail() {
        this.setState({ error: 'Authentication Failed.', loading: false });
      }

      onLoginSuccess() {
        this.setState({
          email: '',password: '',error: '',loading: false});
      }
     render
            ....
                value={this.state.email}
                onChangeText={email => this.setState({ email })}
              />
            </CardSection>
            <CardSection>
              <Input
                ...
                onChangeText={password => this.setState({ password })}
              />

【问题讨论】:

  • 你可以通过你的 catch 块传递一个错误来调试它,比如catch(error =&gt; {console.log(error);} - 让我们知道错误是什么

标签: javascript firebase react-native firebase-authentication


【解决方案1】:

尝试捕捉错误并控制台记录它。

 onButtonPress() {
        const { email, password } = this.state;
        this.setState({ error: '', loading: true });
        firebase.auth().signInWithEmailAndPassword(email, password)
          .then(this.onLoginSuccess.bind(this))
          .catch((error) => { <===
            console.log(error); <===
            firebase.auth().createUserWithEmailAndPassword(email, password)
              .then(this.onLoginSuccess.bind(this))
              .catch(this.onLoginFail.bind(this));
          });
      }

【讨论】:

    猜你喜欢
    • 2015-07-03
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多