- manual-tasks/[id].tsx: use r.data?.data ?? r.data for detail query to handle API response wrapper envelope, matching list screen pattern - remittances/[id].tsx: same fix — detail query now unwraps correctly - services/api.ts: use STORAGE_KEYS.TOKEN constant instead of hardcoded string literals in SecureStore calls
33 lines
788 B
TypeScript
33 lines
788 B
TypeScript
import axios from 'axios';
|
|
import * as SecureStore from 'expo-secure-store';
|
|
import { API_URL, STORAGE_KEYS } from '../constants';
|
|
|
|
export const api = axios.create({
|
|
baseURL: API_URL,
|
|
timeout: 15000,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
api.interceptors.request.use(async (config) => {
|
|
const token = await SecureStore.getItemAsync(STORAGE_KEYS.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(STORAGE_KEYS.TOKEN);
|
|
await SecureStore.deleteItemAsync('fiberops_tenant');
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default api;
|