我需要帮助。我不知道如何检测 phoneNumber 是否已成功链接到用户。如果操作成功,我想重定向到其他页面。我的代码是这样的。*我的代码有效,但如果我添加一个函数来重定向它不起作用。function verifyNumber(){var user = firebase.auth().currentUser;var phoneNumber = document.getElementById('phoneNumber');var signInButtonElement = document.getElementById('sign-in-button');var inputCode = document.getElementById('code');var codeButton = document.getElementById('confirm-code');if(!user.phoneNumber){ // You also need to provide a button element signInButtonElement // which the user would click to complete sign-in. // Get recaptcha token. Let's use invisible recaptcha and hook to the button. var appVerifier = new firebase.auth.RecaptchaVerifier( signInButtonElement, {size: 'invisible'}); // This will wait for the button to be clicked the reCAPTCHA resolved. user.linkWithPhoneNumber(phoneNumber.value, appVerifier) .then(function(confirmationResult) { // Ask user to provide the SMS code. phoneNumber.style.display = 'none'; signInButtonElement.style.display = 'none'; //inputCode.style.display = 'inline-block' //codeButton.style.display = 'inline-block' var code = window.prompt('Provide your SMS code'); // Complete sign-in. return confirmationResult.confirm(code); //updateStatus() doesnt work }); } } function updateStatus(){ var user = firebase.auth().currentUser; if(user.phoneNumber){ window.location.href = "../home/home.html"; }else{ alert('Ha ocurrido un error'); } }
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
在检查和重定向之前,您必须等待异步功能confirmationResult.confirm完成。
user.linkWithPhoneNumber(phoneNumber.value, appVerifier)
.then(function(confirmationResult) {
// Ask user to provide the SMS code.
phoneNumber.style.display = 'none';
signInButtonElement.style.display = 'none';
//inputCode.style.display = 'inline-block'
//codeButton.style.display = 'inline-block'
var code = window.prompt('Provide your SMS code');
// Complete sign-in.
return confirmationResult.confirm(code);
})
.then(() => {
// Wait for linking to complete before redirecting.
updateStatus();
});
}
添加回答
举报
0/150
提交
取消