【问题标题】:Firebase getIdToken() + React Native + refreshing user database to authenticate email verified userFirebase getIdToken() + React Native + 刷新用户数据库以验证电子邮件验证用户
【发布时间】:2017-12-02 06:59:38
【问题描述】:

我正在开发一个 React Native 项目并使用 Firebase。

我正试图让用户在验证其电子邮件地址后登录。我向用户发送了一封注册电子邮件,用户单击验证链接以验证自己,然后应该能够登录。我当前的代码允许用户登录后验证,但只有在我刷新应用程序之后。我希望用户在验证后登录而不刷新应用程序。 我发现我可以在 Firebase 中使用 getIdToken() 来实现它。但不知何故,我似乎无法让它工作。任何指示我在哪里做错了什么?提前致谢。

我的这个函数的代码 sn-p 是:

_login = () =>{
var me = this;
firebaseRef.auth().onAuthStateChanged(function(user) {
  if(user){
    user.getIdToken(forceRefresh).then(function() {
      if( firebaseRef.auth().currentUser.emailVerified){
      firebaseRef.auth().signInWithEmailAndPassword(this.state.email, this.state.password).then(function(){
        // some function here, which is working perfectly
      }, 
      function(error) {
        alert('The username or password is incorrect');
          console.log(error);
      })
      }
      else {
        alert('Your email has not been verified');
      }
    },
    function(error) {
      alert('There is an email verification error');
        console.log(error);
    })
  } 
}
  ) 
}

【问题讨论】:

    标签: firebase react-native firebase-authentication


    【解决方案1】:
        firebase.auth().signInWithEmailAndPassword(email, password)
                    .then(() => {
                        if(firebase.auth().currentUser.emailVerified === false) {
                            Alert.alert('Message')
                        } else {
    Actions.screen()
                    }})
                    .catch(erro => Alert.alert(erro);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-23
      • 2018-02-13
      • 2021-10-10
      • 2022-08-07
      • 2020-12-26
      • 2020-09-08
      • 2019-03-15
      • 2020-08-06
      相关资源
      最近更新 更多