chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
+43
View File
@@ -0,0 +1,43 @@
import axios from 'axios';
import { getToken, getAdminToken } from '../auth/tokenStorage';
// Change this to your server IP/domain
export const API_BASE_URL = 'http://localhost:8080';
const apiClient = axios.create({
baseURL: API_BASE_URL,
timeout: 15000,
headers: {
'Content-Type': 'application/json',
},
});
// Request interceptor: attach JWT token
apiClient.interceptors.request.use(async (config) => {
// Determine which token to use based on URL
const isAdminRoute = config.url?.includes('/api/v2/') ||
config.url?.includes('/api/v1/cabine/') ||
config.url?.includes('/api/v1/livreur/');
const token = isAdminRoute
? await getAdminToken()
: await getToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Response interceptor: handle common errors
apiClient.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
console.log('Session expirée');
}
return Promise.reject(error);
}
);
export default apiClient;