You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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. };