igcrmmobile/src/services/api.ts.bak

24 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

import axios from 'axios';
import AsyncStorage from '@react-native-async-storage/async-storage';
// Replace with your local machine's IP (for Android Emulator use 10.0.2.2)
// For physical device, use your machine's LAN IP e.g., 192.168.1.X
const API_URL = 'http://192.168.29.100:3000';
const api = axios.create({
baseURL: API_URL,
headers: {
'Content-Type': 'application/json',
},
});
api.interceptors.request.use(async (config) => {
const token = await AsyncStorage.getItem('userToken');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
export default api;