【发布时间】:2020-09-18 17:53:57
【问题描述】:
enter code here
Submit=e=>{
e.preventDefault();
let data="";
this.setUpRecaptcha();
// window.alert("Appointment Done Successfully at time "+this.state.curTime+" ! Go to the home page");
var phoneNumber = this.state.contact;
console.log(phoneNumber)
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
var code = window.prompt("enter OTP")
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
alert("OTP is verified!!!");
this.data="doneit";
// ...
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
// ...
alert("OTP verification failed");
});
}).catch(function (error) {
// Error; SMS not sent
// ...
alert("cann't send OTP use another Contact number")
});
//Data storage code
if(this.data=='doneit'){
firebase.database().ref("appoinment").push(
{
name:this.state.name,
email:this.state.email,
contact:this.state.contact,
age:this.state.age,
gender:this.state.gender,
Appointdate:this.state.Appointdate,
Description:this.state.Description,
date:this.state.curTime
}
);
alert(" Data saved successfully");
window.location.reload(false);
}
else{
alert("failed");
}
};
我的代码如上图所示。我希望以这样的方式执行,即如果在提交表单后将调用 Submit()。然后它将检查 OTP 验证。如果成功,则只有数据将存储在 firebase 实时数据库中
- 列表项
【问题讨论】:
标签: reactjs firebase firebase-realtime-database firebase-authentication react-router