Firebase电话身份验证和链接

我正在尝试将我的电话号码与我的电子邮件密码验证相关联。 所以我建立我的注册使用以下步骤:

  • 用户输入电子邮件地址和密码。
  • 然后我调用firebase.auth().createUserWithEmailAndPassword(values.email, values.password)
  • 那么我需要链接当前帐户和电话号码,所以我使用firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxxxx", xxx)
  • 但是,我没有看到任何链接。 2个帐户在我的Firebase控制台中创建,当前用户只在他的详细信息中包含电话号码。 当我再次用电子邮件和密码登录并检查用户的详细信息时,电话号码不存在!

    请在下面找到我的代码:

    onSubmit(values) {
        this.props.firebase.auth().createUserWithEmailAndPassword(values.email, values.password).then((user) => {
            //send recaptchaverifier
            window.recaptchaVerifier.verify();
    
        }).catch((error) => {
            console.log(error);
        });
    }
    
    
    window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('submit-button', {
            'size': 'invisible',
            'callback': function(response){
             //called when we call "window.recaptchaverifier.verify() in 
             //onSubmit function
                var xxx = window.recaptchaVerifier;
    
                this.props.firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxx", xxx)
                    .then((verificationId) => {
                        console.log('inside');
                        console.log(resp);
                        var verificationCode = window.prompt('Please enter the verification ' +
                            'code that was sent to your mobile device.');
                        return firebase.auth.PhoneAuthProvider.credential(resp.verificationId,
                            verificationCode);
                    }).then((phoneCredential) => {
                    console.log("RESULT OF AUTH", phoneCredential);
                    console.log("USER INFO: ", this.props.firebase.auth().currentUser);
                    return this.props.firebase.auth().signInWithCredential(phoneCredential)
                }).catch((error) => {
                    console.log("ERRORS: ", error);
                }).catch((error) => {
                    console.log("ERROR", error)
                });
            }.bind(this)
        });
    

    您正在使用创建新用户的电话凭据调用signInWithCredential 。 您需要执行以下操作:

    firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxx", xxx)
      .then((confirmationResult) => {
        // At this point SMS is sent. Ask user for code.
        let code = window.prompt('Please enter the 6 digit code');
        return confirmationResult.confirm(code);
      })
      .then((result) {
        // Phone credential now linked to current user.
        // User now can sign in with email/pass or phone.
      });
      .catch((error) => {
        // Error occurred.
      });
    
    链接地址: http://www.djcxy.com/p/32343.html

    上一篇: Firebase Phone authentication and Linking

    下一篇: Firebase verify multiple email addresses for the same user