Skip to content

Instantly share code, notes, and snippets.

@bmnepali
Created March 9, 2019 05:07
Show Gist options
  • Save bmnepali/fa0603d97e7fa0eb2d7ac9be7e50224b to your computer and use it in GitHub Desktop.
Save bmnepali/fa0603d97e7fa0eb2d7ac9be7e50224b to your computer and use it in GitHub Desktop.
Redirect to login on 401 in react using axios
import axios from 'axios';
import Config from './app.config';
const instance = axios.create({
baseURL: Config.apiPath,
});
/**
* Catch the AunAuthorized Request
*/
instance.interceptors.response.use((response) => response, (error) => {
if (error.response.status === 401) {
window.location = '/auth/login';
}
});
export default instance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment