bfd35905c9
- Added favicon and icon assets for the mobile app. - Implemented EmotionPicker component for selecting emotions with child options. - Created hooks for fetching emotions, feeds, and rapport data. - Established API service for handling requests and authentication. - Integrated Zustand for state management of user authentication. - Defined color palette for the application. - Set up TypeScript types for various entities including User, Emotion, and Feed. - Configured Babel and TypeScript for the mobile project. - Added package.json with necessary dependencies for Expo and React Native.
38 lines
879 B
TypeScript
38 lines
879 B
TypeScript
import axios from 'axios';
|
|
import * as SecureStore from 'expo-secure-store';
|
|
import { Platform } from 'react-native';
|
|
|
|
const API_URL = Platform.select({
|
|
android: 'http://10.0.2.2:8000/api/v1',
|
|
ios: 'http://localhost:8000/api/v1',
|
|
default: 'http://localhost:8000/api/v1',
|
|
});
|
|
|
|
const api = axios.create({
|
|
baseURL: API_URL,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
},
|
|
});
|
|
|
|
api.interceptors.request.use(async (config) => {
|
|
const token = await SecureStore.getItemAsync('cesizen_token');
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|
|
|
|
api.interceptors.response.use(
|
|
(response) => response,
|
|
async (error) => {
|
|
if (error.response?.status === 401) {
|
|
await SecureStore.deleteItemAsync('cesizen_token');
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default api;
|