【问题标题】:How to Invoke Firebase in Reactnative app?如何在 React Native 应用程序中调用 Firebase?
【发布时间】:2018-09-14 09:38:53
【问题描述】:

我正在尝试使用 Firebase 电子邮件和密码登录方法为我的应用创建登录信息。当我尝试调用createUserWithEmailAndPasswordsignInWithEmailAndPassword 时,这些方法没有被调用。 如何验证 reactnative 中的 firebase 方法调用。

<Button onPress={this.onButtonPress.bind(this)}>Log In</Button> 

onButtonPress(){
    const { email, password } = this.state;

    this.setState({error: ''});
    console.log(email + ' ' + password); //==> this executes
    firebase.auth().signInWithEmailAndPassword(email, password)
    .then(function(){
      console.log('sign insuccess'); //==> no execution
    })
    .catch(() => {
      firebase.auth().createUserWithEmailAndPassword(email, password)
      .then(function(){
        console.log('create user success'); //==> no execution
      })
      .catch(() => {
        this.setState({ error: 'Authentication Failed.' }); //==> no execution
      });
    });
    console.log('buttonpress finished'); 
}

【问题讨论】:

  • 您是否在 Firebase 控制台中启用了电子邮件方法?
  • 你也完成了Web Setup这一步吗?
  • 我已经添加了网络设置并启用了电子邮件和密码作为登录方法,但我仍然无法调用 firebase auth
  • @PeterHaddad 如何验证 firebase 本身是否已初始化我无法在 react native 中调用任何 firbase 方法。

标签: android reactjs firebase react-native firebase-authentication


【解决方案1】:

你应该试试这个它对我有用, 希望对你有帮助

尝试signInAndRetrieveDataWithEmailAndPassword 而不是signInWithEmailAndPassword

已编辑

signInAndRetrieveDataWithEmailAndPassword 现在已弃用,因此您应该使用signInWithEmailAndPassword 否则会出错。

谢谢@mshikher。

【讨论】:

  • 是的,signInAndRetrieveDataWithEmailAndPassword 有效,idk y signInWithEmailAndPassword 无效。还是不行。
  • 重新安装应用后,signInWithEmailAndPassword 也有效。
  • firebase.auth.Auth.prototype.signInAndRetrieveDataWithEmailAndPassword 已弃用。请改用 firebase.auth.Auth.prototype.signInWithEmailAndPassword。我在使用 signInAndRetrieveDataWithEmailAndPassword 时收到此错误
  • 是的,你是对的 @mshikher signInAndRetrieveDataWithEmailAndPassword 在 2018 年 9 月后被弃用。现在我们应该使用 signInWithEmailAndPassword。谢谢@mshikher
  • firebase 的这些功能是否可以与 Xcode Emulator 一起使用?每当我使用 firebase 库调用这些函数时,它都会给我一个错误?
猜你喜欢
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多