import { fetcher, createFetcher } from '@thewebformula/lithe';
fetcher('/get', { interceptors: {
auth(config) {
config.headers.Authorization = 'Bearer token';
return config;
},
before(config) {
return config;
}
});
fetcher('/get', { interceptors: {
async auth(config) {
const refreshResponse = await fetcher('/refreshToken', {
headers: { Authorization: 'Bearer refresh_token' }
});
config.headers.Authorization = await refreshResponse.text();
return config;
}
});
const fetcherInstance = createFetcher({
baseUrl: '',
headers: {
Authorization: 'Bearer token'
},
interceptors: {
auth(config) {
config.headers.Authorization = 'Bearer token';
return config;
},
before(config) {
return config;
}
}
});
fetcherInstance('/get');
fetcherInstance('/get', {}, interceptors: {
auth(config) {
config.headers.Authorization = 'Bearer token';
return config;
},
before(config) {
config.headers.Authorization = 'Bearer token';
return config;
}
});