22 lines
474 B
TypeScript
22 lines
474 B
TypeScript
|
|
import axios from 'axios'
|
||
|
|
|
||
|
|
const baseURL = (import.meta.env.VITE_BACKEND_URL as string) || 'http://localhost:8080';
|
||
|
|
|
||
|
|
const api = axios.create({
|
||
|
|
baseURL,
|
||
|
|
withCredentials: true,
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
export const setAuthToken = (token?: string) => {
|
||
|
|
if (token) {
|
||
|
|
api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||
|
|
} else {
|
||
|
|
delete api.defaults.headers.common['Authorization'];
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export default api;
|