Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hande logout when expired token in axios interceptors but not redirect to login page #240

Open
nguyenducdan96 opened this issue Oct 4, 2018 · 2 comments

Comments

@nguyenducdan96
Copy link

nguyenducdan96 commented Oct 4, 2018

Hi, I'm trying to logout when expired token.

axios.interceptors.response.use(
  response => response,
  error => {
    const { config, status } = error.response;
    const originalRequest = config;
    const refreshToken = localStorage.getItem(refreshTokenKey);
    if (status === 401) {
      return apiRefreshAccessToken(refreshToken)
        .then(response => {
          localStorage.setItem(accessTokenKey, response.data.access_token);
          return axios(originalRequest);
        })
        .catch(err => {
          configureStore().dispatch(logout());
          return err;
        });
    }
    return Promise.reject(error);
  },
);
---------------------------------------------------------------------------------
import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect';
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
import { UrlPath } from 'commons/constants';

const locationHelper = locationHelperBuilder({});

export const userIsAuthenticated = connectedRouterRedirect({
  redirectPath: `${UrlPath}/`,
  authenticatedSelector: state => state.toJS().login.idToken !== null,
  wrapperDisplayName: 'UserIsAuthenticated',
});

export const userIsNotAuthenticated = connectedRouterRedirect({
  redirectPath: (state, ownProps) =>
    locationHelper.getRedirectQueryParam(ownProps) ||
    `${UrlPath}/fleet-dashboard`,
  allowRedirectBack: false,
  authenticatedSelector: state => state.toJS().login.idToken === null,
  wrapperDisplayName: 'UserIsNotAuthenticated',
});

when dispatch logout action, idToken null but not redirect login page.
Thanks

@feawesome
Copy link

hi ~ has the problem been solved ? I have the same problem,can we talk about it?My email is returnzp@gmail.com

@bionicvapourboy
Copy link

How you are referencing the HoC inside your routing ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants