我正在使用 firebase .signInWithEmailAndPassword(email, password).then()
在 react-native Android 项目中进行身份验证。
我有在 onPress 按钮事件上调用的函数。身份验证确实发生了,但由于某种原因,除非我点击屏幕上的其他地方,否则 .then()
不会触发。它会很高兴地等待 5 分钟,直到我点击按钮以外的其他地方触发。
我可以看到身份验证正在进行中。它只是挂起的 .then()
promise ,直到焦点从按钮上移开。
我使用的是 react-native 0.59.5 和 firebase 5.1.0 节点库。我已经尝试对每个步骤进行 console.logging,很明显 then()
是它失败的地方。奇怪的是 catch()
立即起作用。
export const loginUser = ({ email, password }) => {
return dispatch => {
dispatch({ type: LOGIN_USER })
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then(user => loginUserSuccess(dispatch, user))
.catch(() => {
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(user => loginUserSuccess(dispatch, user))
.catch(loginUserFail(dispatch))
})
}
}
const loginUserFail = dispatch => {
dispatch({ type: LOGIN_USER_FAIL })
}
const loginUserSuccess = (dispatch, user) => {
console.log('Firing success')
dispatch({
type: LOGIN_USER_SUCCESS,
payload: user
})
}
在上面的示例中,如果身份验证失败,loginUserFail 将立即运行,但 loginUserSuccess 将无限期地等待,直到我点击应用程序中的其他地方。
最佳答案
您是否在 Chrome 浏览器中打开了远程调试器? 关闭它(调试器),在模拟器中重新加载应用程序,它将按预期工作。
关于javascript - Firebase signInWithEmailAndPassword 直到 UI 焦点更改后才触发 .then(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55855752/