Firebase signInWithEmailAndPassword 在 UI 焦点更改之前不会触发 .then()
Posted
技术标签:
【中文标题】Firebase signInWithEmailAndPassword 在 UI 焦点更改之前不会触发 .then()【英文标题】:Firebase signInWithEmailAndPassword not firing .then() until after UI focus changes 【发布时间】:2019-09-15 06:25:43 【问题描述】:我在 react-native android 项目中使用 firebase .signInWithEmailAndPassword(email, password).then()
进行身份验证。
我在 onPress 按钮事件上调用了该函数。身份验证确实发生了,但由于某种原因,.then()
不会触发,除非我点击屏幕上的其他位置。它会很高兴地等待 5 分钟,直到我点击按钮以外的某个地方来触发。
我可以看到正在进行身份验证。只是 .then()
承诺会一直挂起,直到焦点从按钮上移开。
我正在使用 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 将无限期地等待,直到我点击应用程序中的其他位置。
【问题讨论】:
我也有同样的问题,请问您找到解决方案了吗? 关于这个主题的任何消息,我拒绝接受我在使用这个 promise-pattern 时无法调试。 我对 @angular/fire 的库有同样的问题。 longUserFail 立即执行,但成功将无限期等待。 【参考方案1】:您是否在 Chrome 浏览器中打开了远程调试器? 关闭它(调试器),在模拟器中重新加载应用程序,它将按预期工作。
【讨论】:
现代开发的神器解决方案!谢谢你,先生【参考方案2】:只需在您的应用程序中停止远程调试器,希望这会有所帮助
【讨论】:
【参考方案3】:尝试删除“then”承诺:
firebase.auth().signInWithEmailAndPassword(email, password)
.catch(error =>
dispatch(loginUserFail(error));
);
然后尝试使用此命令创建一个动作:
firebase.auth().onAuthStateChanged(user =>
if (user)
console.log('success sign in');
dispatch(loginUserSuccess(user));
else
// No user is signed in.
);
【讨论】:
以上是关于Firebase signInWithEmailAndPassword 在 UI 焦点更改之前不会触发 .then()的主要内容,如果未能解决你的问题,请参考以下文章