我创建了jwt中间件
export function jwt({ dispatch, getState }) {
return (next) => (action) => {
const authReducer = getState().AuthorizationReducer;
if(authReducer && authReducer.token.accessToken) {
const {
refreshToken,
time,
} = getState().AuthorizationReducer.token;
const details = {
client_id: authReducer.getToken.clientId,
client_secret: authReducer.getToken.clientSecret,
grant_type: 'refresh_token',
refresh_token: refreshToken
};
let now = +Moment(Date.now());
if (now > time) {
const queryString = Object.keys(details).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(details[k])}`).join('&');
return next(getAccessTokenByRefreshToken(queryString));
}
}
return next(action);
};
}
但我从未进入过getAccessTokenByRefreshToken。看起来像是:
export function getAccessTokenByRefreshToken(queryString) {
return (dispatch, getState) => {
dispatch(refreshTokenStart());
fetch(`${API_URL}oauth/v2/token?${queryString}`, {
method: 'GET'
})
.then(res => {
if (res.status >= 200 && res.status < 300) {
return res.json();
}
})
.then(json => {
console.log(json);
debugger;
dispatch(refreshTokenComplete(json));
})
.catch((err) => {
dispatch(refreshTokenError(err.error));
Actions.launch();
});
}
}
我在applyMiddleware函数中使用了redux和aply我的中间件。 问题是我如何发布我的行动?