Mobile App design
Run Tests on Branches / Detect Changes (push) Successful in 10s
Run Tests on Branches / Backend Tests (push) Successful in 2m12s
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m47s

This commit is contained in:
Ichitux
2026-07-09 13:33:54 +02:00
parent 5f604b11ba
commit 2f36ef685d
32 changed files with 1793 additions and 926 deletions
+18 -7
View File
@@ -2,32 +2,43 @@ import axios from 'axios';
import * as SecureStore from 'expo-secure-store';
import { config } from '../constants/config';
const SESSION_KEY = 'session_id';
export const api = axios.create({
baseURL: config.API_BASE_URL,
timeout: 10000,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
});
// Request interceptor - add auth token
// Request interceptor - restore session cookie from SecureStore
api.interceptors.request.use(
async (axiosConfig) => {
const token = await SecureStore.getItemAsync('auth_token');
if (token) {
axiosConfig.headers.Authorization = `Bearer ${token}`;
const session = await SecureStore.getItemAsync(SESSION_KEY);
if (session) {
axiosConfig.headers.Cookie = session;
}
return axiosConfig;
},
(error) => Promise.reject(error)
);
// Response interceptor - handle errors
// Response interceptor - capture and persist session cookie from responses
api.interceptors.response.use(
(response) => response,
(response) => {
const setCookie = response.headers['set-cookie'];
if (setCookie) {
const cookieStr = Array.isArray(setCookie) ? setCookie[0] : setCookie;
const sessionId = cookieStr.split(';')[0];
SecureStore.setItemAsync(SESSION_KEY, sessionId);
}
return response;
},
async (error) => {
if (error.response?.status === 401) {
await SecureStore.deleteItemAsync('auth_token');
await SecureStore.deleteItemAsync(SESSION_KEY);
}
return Promise.reject(error);
}