Skip to content

Simple-rest package: bearer auth not being used for requests. #5880

Closed Answered by startupskateboard
startupskateboard asked this question in Q&A
Discussion options

You must be logged in to vote

I found the solution. Inside App.tsx:

// Create a custom axios instance
const axiosInstance = axios.create({
  baseURL: "https://api.com", // Replace with your API URL
});

// Function to add token to requests

axiosInstance.interceptors.request.use(
  (config) => {
    // Retrieve the token from wherever it's stored
    const token = localStorage.getItem('access_token');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

Then update the dataprovider:

      `      dataProvider={dataProvider("https://api.com", axiosInstance)}          

`

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by startupskateboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant