此saga适用于LOGIN_SUCCESS
操作并正确保留数据。然而,之后它永远不会对LOGOUT_SUCCESS
function *persistAccount() {
while (true) {
const result = yield take([actions.LOGIN_SUCCESS, actions.USER_UPDATED, actions.LOGOUT_SUCCESS])
console.info("Got persist action")
switch (result.type) {
case actions.LOGIN_SUCCESS:
case actions.USER_UPDATED:
console.info("Updating credentials")
if (result.access_token) {
localStorage["access_token"] = result.access_token
}
if (result.user) {
localStorage["user"] = JSON.stringify(result.user)
}
break
case action.LOGOUT_SUCCESS:
debugger
console.info("Clearing credentials")
localStorage.removeItem("access_token")
localStorage.removeItem("user")
break
}
}
console.info("!!!!!!!!!!!!!!!!!!!EXIT")
}
它也永远不会完成,因为这会将最后一行的文本打印到控制台。
怎么回事?
答案 0 :(得分:0)
我无法相信这花了很长时间才能看到。这是一个错字:
case action.LOGOUT_SUCCESS:
需要:
case actions.LOGOUT_SUCCESS: // "actions" instead of "action"