Skip to content

Instantly share code, notes, and snippets.

@nhattruongniit
Forked from srph/expired.js
Created June 24, 2019 07:10
Show Gist options
  • Select an option

  • Save nhattruongniit/df2ad362659fe3c1e76e6012e1684e1d to your computer and use it in GitHub Desktop.

Select an option

Save nhattruongniit/df2ad362659fe3c1e76e6012e1684e1d 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment