您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

authenticationMiddleware.js 612B

12345678910111213141516171819202122
  1. import { attachPostRequestListener } from "../../request";
  2. import { logoutUser } from "../actions/login/loginActions";
  3. export const authenticationMiddlewareInterceptorName =
  4. "AUTHENTICATION_MIDDLEWARE";
  5. export default ({ dispatch }) =>
  6. (next) =>
  7. (action) => {
  8. attachPostRequestListener((error) => {
  9. if (!error.response) {
  10. return Promise.reject(error);
  11. }
  12. if (error.response.status === 401) {
  13. dispatch(logoutUser());
  14. return Promise.reject(error);
  15. }
  16. return Promise.resolve();
  17. }, authenticationMiddlewareInterceptorName);
  18. next(action);
  19. };