From e0f22b6c5a321a59b3db68bb566789a785adc376 Mon Sep 17 00:00:00 2001 From: IluaAir Date: Mon, 6 Oct 2025 23:09:25 +0300 Subject: [PATCH] add axios client with interceptors --- taskncoffee-app/src/apiv1/client.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 taskncoffee-app/src/apiv1/client.js diff --git a/taskncoffee-app/src/apiv1/client.js b/taskncoffee-app/src/apiv1/client.js new file mode 100644 index 0000000..688fa99 --- /dev/null +++ b/taskncoffee-app/src/apiv1/client.js @@ -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; \ No newline at end of file