【发布时间】:2020-07-31 10:29:07
【问题描述】:
我想使用 firebase 身份验证登录到我的 react 本机应用程序。例如,要使用电子邮件和密码登录,我有以下功能,这基本上是一个 redux 操作:
export const userSignin = (email, password) =>
async dispatch => {
try {
dispatch({ type: 'auth_attempt_started' })
const user = await firebase.auth().signInWithEmailAndPassword(email.trim(), password)
saveUserDataToAsyncStorage(user)
if (!TASKS_SORT_BY && !TASKS_SORT_ORDER)
dispatch(getTasksSortData(user.user.uid))
if (!EMPLOYEES_SORT_BY && !EMPLOYEES_SORT_ORDER)
dispatch(getEmployeesSortData(user.user.uid))
if (!ACCOUNTS_SORT_BY && !ACCOUNTS_SORT_ORDER)
dispatch(getAccountsSortData(user.user.uid))
goToMain()
setTimeout(() => {
dispatch({
type: 'user_signedin',
payload: user
})
}, 100);
}
catch (err) {
dispatch({
type: 'auth_error',
payload: err.toString()
})
}
}
如果登录过程出现问题,此函数会引发错误。 问题是网速慢时,登录成功或失败的时间较长,有时30秒左右,对用户体验非常不利。
问题是:
如果登录过程未完成,我如何在有时可能 10 秒后抛出错误?
谢谢!
【问题讨论】:
标签: javascript firebase react-native settimeout throw