无法读取未定义'refreshToken'的属性

时间:2018-08-27 01:03:29

标签: javascript react-native redux

尝试编写Redux中间件以刷新令牌-我收到“无法读取.refreshToken({refreshToken:refreshToken})上未定义的属性refreshToken。

这实际上怎么可能出错?

 function checkExpiredToken({ getState, dispatch }) {
        return next => action => {
            let user = getState().auth.user;

            if (user && user.refreshToken && moment(user.expiryDate).isBefore(moment())) {
                let refreshToken = user.refreshToken;

                if (refreshToken) {
                    auth0.auth
                        .refreshToken({ refreshToken: refreshToken })
                        .then(credentials => {
                            // Set the Bearer Authorization header on every axios request
                            axios.defaults.headers.common["Authorization"] = `${credentials.tokenType} ${
                                credentials.idToken
                            }`;

                            dispatch({ type: REFRESHED_TOKEN, payload: credentials });
                            next(action);
                        })
                        .catch(console.error);
                }
            } else {
                next(action);
            }
        };
    }

0 个答案:

没有答案