22 lines
607 B
TypeScript
22 lines
607 B
TypeScript
import axios from 'axios';
|
|
import { Platform } from 'react-native';
|
|
import { useAuthStore } from '../store/authStore';
|
|
|
|
const BASE_URL = Platform.OS === 'web' ? 'http://localhost:8000' : 'http://192.168.1.130:8000';
|
|
|
|
const api = axios.create({
|
|
baseURL: BASE_URL, // Use localhost for web, local IP for physical device (Expo Go)
|
|
});
|
|
|
|
// Add interceptor to attach JWT token
|
|
api.interceptors.request.use(async (config) => {
|
|
const token = useAuthStore.getState().token;
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|
|
|
|
export { BASE_URL };
|
|
export default api;
|