verbal-limeV
Refine2y ago
3 replies
verbal-lime

header token auth is not sending in request header

I've got this code import React from "react";
import { DataProvider } from "@refinedev/core";
import axios from "axios";

const axiosInstance = axios.create();

// add token to every request
axiosInstance.interceptors.request.use(
async (config) => {
const token = localStorage.getItem("token");
if (token && config?.headers) {
config.headers.Authorization = Bearer ${token};
}
return config;
},
(error) => {
return Promise.reject(error);
},
);

export const dataProvider = (url: string): DataProvider => ({
getList: async ({ resource }) => {
const response = await axiosInstance.get(${url}/${resource});
const data = response.data;

return {
data,
total: data.length,
};
},

getOne: async () => {
throw new Error("Not implemented");
},

create: async () => {
throw new Error("Not implemented");
},
update: async () => {
throw new Error("Not implemented");
},
deleteOne: async () => {
throw new Error("Not implemented");
},

getApiUrl: () => url,
});

but the request header is not including the bearer token
Was this page helpful?