【发布时间】:2020-02-24 06:12:56
【问题描述】:
正在向firebase发送字符认证。
代码流程是...
- 用户输入电话号码并点击按钮
- 将值发送到服务器并以文本形式发送验证码
- 用户输入验证码并点击按钮
- 认证码值判别
在第二步中,按下按钮将执行signIn()即代码。
const signIn = () => {
auth
.signInWithPhoneNumber(mobileNum, appVerifier)
.then(function(confirmationResult) {
//start
window.confirmationResult = confirmationResult;
confirmationResult
.confirm(authCode)
.then(function(result) {
var user = result.user;
})
.catch(function(error) {
});
//end
})
.catch(function(error) {
console.log(error);
});
};
此时start到end的部分必须在第3步之后(按钮事件之后)执行。
start 中的end 必须等待按钮事件发生。
我该怎么做?
【问题讨论】:
-
您可以将
//end部分移动到内部调用的.then中。 -
@Jai 但是我只能在单击按钮时允许 then 运行吗?
-
看起来你想暂停里面的执行。
confirm通话可以暂停。 -
@Jai authCode 是用户必须输入的值,无法判断是否存在。只能在按钮事件按下时执行。有什么我弄错了吗?
标签: javascript reactjs firebase