chore: initial project scaffold: frontend/src/dataProvider.ts
This commit is contained in:
16
frontend/src/dataProvider.ts
Normal file
16
frontend/src/dataProvider.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import simpleRestProvider from 'ra-data-simple-rest';
|
||||
import { fetchUtils } from 'react-admin';
|
||||
import { getToken } from './authProvider';
|
||||
|
||||
const httpClient = (url: string, options: fetchUtils.Options = {}) => {
|
||||
const token = getToken();
|
||||
const headers = new Headers(options.headers);
|
||||
if (token) {
|
||||
headers.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
return fetchUtils.fetchJson(url, { ...options, headers });
|
||||
};
|
||||
|
||||
const apiUrl = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
export const dataProvider = simpleRestProvider(apiUrl, httpClient);
|
||||
Reference in New Issue
Block a user