首页 > 解决方案 > React + Redux Login

问题描述

I'm finding a problem that I can not find an optimal solution,

Well, the problem involves Redux, when making a request in the Login route, to receive the Token. The middleware that will handle the result of the request always returns with payload = undefined.

If I make any promises using this middleware, it usually returns the result, but when it is login, it tries to do SET before receiving the result.

middleware: https://textuploader.com/dnp0m

Reducer Auth: https://textuploader.com/dnp0q

Reducer Common: https://textuploader.com/dnp0c

Agent: https://textuploader.com/dnp0l

Im Calling the dispatch like this

onSubmit: (cpf, pass) => {
    dispatch({type: LOGIN, payload: agent.Auth.login(cpf, pass)})
},

标签: reactjsloginreduxjwt

解决方案


问题可能出在您的中间件中,当您查看中间件代码时,您正在更新 action.payload 对象本身。

        res => {
            console.log('RESULT', res);
            action.payload = res;
            store.dispatch({ type: ASYNC_END, promise: action.payload });
            store.dispatch(action);
        }

而不是更新 action.payload 值,只需发送 res 值。

       res => {
            console.log('RESULT', res);
            store.dispatch({ type: ASYNC_END, promise: res });
            store.dispatch(action);
        }

推荐阅读