小编Ryu*_*ent的帖子

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

我正在将Firebase .signInWithEmailAndPassword(email, password).then()用于本机Android项目中的身份验证。

我在onPress按钮事件上调用了该函数。身份验证确实进行了,但是由于某些原因,.then()除非我在屏幕上的其他位置点击,否则不会触发身份验证。它将很高兴地等待5分钟,直到我点击除按钮以外的其他位置来触发。

我可以看到验证正在进行中。这只是.then()挂起的承诺,直到焦点从按钮移开。

我正在使用本机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, …
Run Code Online (Sandbox Code Playgroud)

javascript firebase react-native firebase-authentication redux-thunk

5
推荐指数
1
解决办法
309
查看次数