[英]Firebase Phone authentication and Linking
我正在嘗試將我的電話號碼與我的電子郵件密碼身份驗證相關聯。 所以我使用以下步驟建立我的注冊:
firebase.auth().createUserWithEmailAndPassword(values.email, values.password)
firebase.auth().currentUser.linkWithPhoneNumber("+xxxxxxxxxx", xxx)
但是,我沒有看到任何鏈接。 在我的Firebase控制台中創建的2個帳戶和當前用戶僅在其詳細信息中具有電話號碼。 當我再次使用電子郵件和密碼登錄並檢查用戶詳細信息時,電話號碼不存在!
請在下面找到我的代碼:
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.
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.