redux-saga 和 firebase - 无法以干净的方式注销用户

redux-saga and firebase - Can't log the user out in a clean way

作为序言,让我提一下,我在今天之前从未使用过 redux-saga 或 Firebase。我目前正在尝试了解这两种技术。

我可能只是遗漏了一个小概念,但我似乎无法退出以在我的应用程序上工作。我认为我应该使用 call() 来管理传奇中的副作用,但没有任何作用。

这是有问题的故事:

export function* deauthenticateUser() {
  yield takeLatest(DEAUTHENTICATE_REQUEST, function* () {
    try {
      yield call(firebase.auth().signOut)
      yield put({ type: DEAUTHENTICATE })
    }
    catch (error) {
      yield put({
        type: DEAUTHENTICATE_FAILURE,
        payload: error,
        error: true,
      })
    }
  })
}

我确认直接调用 firebase.auth().signout() 有效,只有在使用 call() 时才会出现错误操作。请注意,在发送错误时也没有负载。

I checked in Firebase's documentation,显然 firebase.auth().signout() returns 一个没有内容的承诺。我开始怀疑这是否不是问题所在,也许 redux-saga 不喜欢在使用 call()?

时它的承诺没有结果

如何处理身份验证,尤其是使用 Firebase 和 redux-saga 注销?

根据 NULL SWEΔT 的评论,我不得不打电话给 yield call([firebase.auth(), firebase.auth().signOut])

这是因为 JS 的上下文以及 this 的工作方式。更多详细信息,请阅读 this and this(阅读 call([context, fn], ...args) 的文档)。