Skip to content

Instantly share code, notes, and snippets.

@srph
Last active April 1, 2021 07:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save srph/030db1525b411ada2252 to your computer and use it in GitHub Desktop.
Save srph/030db1525b411ada2252 to your computer and use it in GitHub Desktop.
axios + react-router: handling invalid tokens through axios interceptors
import axios from 'axios';
import cookie from 'cookie-machine';
import {hashHistory} from 'react-router';
axios.interceptors.response.use(null, function(err) {
if ( err.status === 401 ) {
cookie.remove('my-token-key');
hashHistory.push('/login');
}
return Promise.reject(err);
});
@moisesbaddini
Copy link

Attempted import error: 'hashHistory' is not exported from 'react-router'.
in fact, I'm using "react-router-dom": "^5.2.0"

@RacketyWater7
Copy link

this solution seems to be outdated, so it is not working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment