javascript - Firebase signInWithEmailAndPassword 直到 UI 焦点更改后才触发 .then()

标签 javascript firebase react-native firebase-authentication redux-thunk

我正在使用 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/

相关文章:

javascript - Vue Scoped Slots 组件和插槽之间的双向数据绑定(bind)

reactjs - 如何为 AWS 中的嵌套字段设置限制以扩大 DynamoDB 模式?

reactjs - 在调度时使用异步等待

ios - react native 错误 ld : library not found for -lBVLinearGradient

javascript - 如何在模糊时重置堆栈导航器? ( react native , react 导航)

javascript - angularjs - 无法预先选择 list 模型中的复选框

javascript - 如何在事件监听器中使用 <option> 的值来触发函数

Firebase 免费计划托管限制

firebase - Actions on Google 以 "Sorry, I didn' 响应,但未得到任何响应。”

php - 使用 php 从 json 文件中删除父 key