Add profile and login screen + first api logic draft

This commit is contained in:
2025-12-09 18:29:24 +01:00
parent abe14f4c3f
commit 49b6ecadb2
19 changed files with 1046 additions and 810 deletions

43
utils/api.ts Normal file
View File

@ -0,0 +1,43 @@
import axios from 'axios';
import * as SecureStore from 'expo-secure-store';
// CONFIGURAZIONE GATEWAY (Adatta questi valori al tuo DDEV)
// Se sei su emulatore Android usa 10.0.2.2, se su iOS o fisico usa il tuo IP LAN (es 192.168.1.x)
const GATEWAY_BASE_URL = "http://10.0.2.2:PORTA";
export const GATEWAY_ENDPOINT = `${GATEWAY_BASE_URL}/tuo_endpoint_gateway`;
export const GATEWAY_TOKEN = "il_tuo_token_statico_se_esiste";
const api = axios.create({
headers: {
'Content-Type': 'application/json',
},
});
// INTERCEPTOR: Configura ogni chiamata al volo
api.interceptors.request.use(async (config) => {
try {
// 1. Cerchiamo se abbiamo già salvato l'URL finale del backend (post-gateway)
const savedBaseUrl = await SecureStore.getItemAsync('App_URL');
if (savedBaseUrl) {
config.baseURL = savedBaseUrl;
} else {
// Se non c'è, usiamo il gateway come fallback o gestiamo l'errore
// (La logica di init nell'AuthContext dovrebbe averlo già settato)
config.baseURL = GATEWAY_BASE_URL;
}
// 2. Cerchiamo il token utente
const token = await SecureStore.getItemAsync('auth-token');
if (token) {
// Adatta l'header in base al tuo backend (Bearer, x-access-tokens, etc.)
config.headers.Authorization = `Bearer ${token}`;
}
} catch (error) {
console.error("Errore interceptor:", error);
}
return config;
});
export default api;