feat: add API client and services for medicines, pharmacies, auth

This commit is contained in:
Antoni Nuñez Romeu
2026-07-06 11:00:44 +02:00
parent 259bdb1479
commit a5064f2172
5 changed files with 132 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import axios from 'axios';
import * as SecureStore from 'expo-secure-store';
import { config } from '../constants/config';
export const api = axios.create({
baseURL: config.API_BASE_URL,
timeout: 10000,
headers: {
'Content-Type': 'application/json',
},
});
// Request interceptor - add auth token
api.interceptors.request.use(
async (axiosConfig) => {
const token = await SecureStore.getItemAsync('auth_token');
if (token) {
axiosConfig.headers.Authorization = `Bearer ${token}`;
}
return axiosConfig;
},
(error) => Promise.reject(error)
);
// Response interceptor - handle errors
api.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response?.status === 401) {
await SecureStore.deleteItemAsync('auth_token');
}
return Promise.reject(error);
}
);
export default api;