[英]Firebase Phone authentication and Linking
i'm trying to link my phone number with my email password authentication. 我正在尝试将我的电话号码与我的电子邮件密码身份验证相关联。 So i build my registration using below steps:
所以我使用以下步骤建立我的注册:
firebase.auth().createUserWithEmailAndPassword(values.email, values.password)
firebase.auth().createUserWithEmailAndPassword(values.email, values.password)
firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxxxx", xxx)
firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxxxx", xxx)
however, i don't see any linking. 但是,我没有看到任何链接。 2 accounts created in my firebase console and the current user have phone number only in his details.
在我的Firebase控制台中创建的2个帐户和当前用户仅在其详细信息中具有电话号码。 When I log in with email and password again and check user details the phone number is not there !!!
当我再次使用电子邮件和密码登录并检查用户详细信息时,电话号码不存在!
Please find my code below: 请在下面找到我的代码:
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)
});
You are calling signInWithCredential
using the phone credential which creates a new user. 您正在使用创建新用户的电话凭据来调用
signInWithCredential
。 You need to do the following: 您需要执行以下操作:
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.
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.