Created
May 13, 2020 13:52
-
-
Save jamiehaywood/cd8d03fc88b3ce55a094b0a5b03be48f to your computer and use it in GitHub Desktop.
Axios Key Rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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