refactor: add AuthGuard component and fix API client empty response handling

- Add reusable AuthGuard component for protected routes
- Move auth logic from index.tsx to (tabs)/_layout.tsx via AuthGuard
- Fix ApiClient to handle empty responses (204 No Content)
- Use useFocusEffect in chat.tsx to load messages after auth is ready
- Extract getDateKey() helper function in calendar.tsx
This commit is contained in:
2026-01-25 13:03:17 +01:00
parent 43d40b46d7
commit a42e2a7c1c
7 changed files with 112 additions and 65 deletions

View File

@@ -55,7 +55,12 @@ async function request<T>(
}
apiLogger.debug(`${method} ${endpoint} - ${response.status} (${duration}ms)`);
return response.json();
const text = await response.text();
if (!text) {
return undefined as T;
}
return JSON.parse(text);
} catch (error) {
const duration = Math.round(performance.now() - start);
apiLogger.error(`${method} ${endpoint} failed (${duration}ms): ${error}`);