rival-black
rival-black10mo ago

dataProvider is not sending any request after adding axios instance

I have configured an axios instance to handle auth in headers, when I pass it to the dataProvider in the Refine component, no request is sent when entering any view. What am I doing wrong?
4 Replies
kapa.ai
kapa.ai10mo ago
Hi @jaoc1811. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: Sorry @jaoc1811, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist: Perhaps try again in 15mins?
rival-black
rival-black10mo ago
ok! after trying some things, I have noticed that the requests stop to send when i use axiosInstance.interceptors.request.use to configure the headers of the request I'm doing it as you say in the docs
axiosInstance.interceptors.request.use((request: AxiosRequestConfig) => {
// Retrieve the token from local storage
const token = JSON.parse(localStorage.getItem("auth"));
// Check if the header property exists
if (request.headers) {
// Set the Authorization header if it exists
request.headers["Authorization"] = `Bearer ${token}`;
} else {
// Create the headers property if it does not exist
request.headers = {
Authorization: `Bearer ${token}`,
};
}

return request;
});
axiosInstance.interceptors.request.use((request: AxiosRequestConfig) => {
// Retrieve the token from local storage
const token = JSON.parse(localStorage.getItem("auth"));
// Check if the header property exists
if (request.headers) {
// Set the Authorization header if it exists
request.headers["Authorization"] = `Bearer ${token}`;
} else {
// Create the headers property if it does not exist
request.headers = {
Authorization: `Bearer ${token}`,
};
}

return request;
});
are you there now?
fair-rose
fair-rose10mo ago
Hey @jaoc1811, have you been able to resolve the issue? I've tried the code snippet you've provided and had no issue about the requests 🤔 Can you check if you return the request in every condition? This issue will happen if any of the code paths doesn't return the request object in the interceptor fn
rival-black
rival-black10mo ago
I will check it! I found the error, the JSON.parse functions was failing so the request was not returning Thank you!