I am currently doing a project where I need to use axios interceptors. I have watched several guides and read some instructions. Sadly, when I try to implement the interceptors, they do not work. What I am trying to do is at least see if the request has been send. However, the main goal is to check if the current token has expired and assign a new one.
Here is the assignment of axiosInstance with some data:
import axios from "axios";
const axiosInstance = axios.create({
baseURL: "http://142.93.134.108:1111/me",
headers: {
Authorization: "Bearer " + localStorage.getItem("accessToken"),
},
});
export default axiosInstance;
And here is code from one of the components where I try to send the request right when it mounts:
componentDidMount() {
axiosInstance.interceptors.response.use(
function (response) {
return response;
},
function (error) {}
);
}
I understand that I probably do not use interceptors properly, so if possible could you please send some great resources to understand this topic.