Skip to content

Instantly share code, notes, and snippets.

@jamiehaywood
Created May 13, 2020 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiehaywood/cd8d03fc88b3ce55a094b0a5b03be48f to your computer and use it in GitHub Desktop.
Save jamiehaywood/cd8d03fc88b3ce55a094b0a5b03be48f to your computer and use it in GitHub Desktop.
Axios Key Rotation
import axios from "axios";
import { getHeaders } from "./auth/getHeaders";
import { updateTokens } from "./auth/updateTokens";
// https://github.com/axios/axios/issues/1383
const customAxios = axios.create({
baseURL: process.env.REACT_APP_CAPTURAPI,
});
customAxios.interceptors.response.use((response) => {
let { data } = response;
updateTokens(data.authToken, data.refreshToken);
return response;
});
customAxios.interceptors.request.use((config) => {
config.headers = { ...getHeaders() };
return config;
});
export default customAxios;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment