尝试编写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);
}
};
}