const signIn = async e => {
var recaptcha = new firebase.auth.RecaptchaVerifier('recaptcha');
var number = '+91'+mobile;
firebase.auth().signInWithPhoneNumber(number, recaptcha).then( function(e) {
var code = prompt('Enter the otp', '');
if(code === null)
{
return false;
}
e.confirm(code).then(function (result) {
console.log(result.user);
alert("INSIDE");
return true;
}).catch(function (error) {
console.error( error);
});
})
.catch(function (error) {
console.error( error);
return false;
});
}
和其他功能
const func1 = async e => {
alert("OUTSIDE1");
var check=await signIn();
if(check)
{
alert("true value");
}
else
{
alert("false value");
}
输出始终为-
输出1
错误值
然后OTP代码被执行?有人能帮助进行必要的更改以使OTP代码同步吗?
您没有向异步函数的调用方返回适当的promise。你可能想写:
return firebase.auth().signInWithPhoneNumber(...).then(...)
更好的是,由于您使用的是async/await,只需在signIn
函数中等待signInWithPhoneNumber
的结果,并完全避免使用then()/catch()
。