add axios client with interceptors
This commit is contained in:
23
taskncoffee-app/src/apiv1/client.js
Normal file
23
taskncoffee-app/src/apiv1/client.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from 'axios';
|
||||
import { API_BASE_URL, API_V1_PREFIX } from './ApiSources';
|
||||
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: `${API_BASE_URL}${API_V1_PREFIX}`,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
client.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
);
|
||||
export default client;
|
||||
Reference in New Issue
Block a user