'use server' import { getSessionData } from '@/app/lib/session'; import { localDevelopmentUrl } from '@/app/lib/definitions'; const API_BASE_URL = process.env.NODE_ENV === 'development' ? localDevelopmentUrl : 'http://no_copy_app:8080'; const FRUITS_URL = 'https://www.fruityvice.com/api/fruit/'; const ALL = 'all'; export async function fetchFruits() { try { const response = await fetch(FRUITS_URL + ALL, { 'method': 'GET' }); let parsed = await response.json(); return parsed; } catch (error) { console.error('Error:', error); throw new Error('Failed to fetch fruits data.'); } } export async function fetchFruit(id: number) { try { const response = await fetch(FRUITS_URL + id, { 'method': 'GET' }); let parsed = await response.json(); return parsed; } catch (error) { console.error('Error:', error); throw new Error('Failed to fetch fruits data.'); } } export async function getUserData() { const userEmail = await getSessionData('email'); const token = await getSessionData('token'); try { const response = await fetch(`${API_BASE_URL}/api/user?email=${userEmail}`, { method: 'GET', headers: { "Content-Type": "application/json", "Accept": "application/json", "Authorization": `Bearer ${token}`, } }); if (response.ok) { return await response.json(); } } catch (error) { console.error('error'); } }