From a7d06570d6c7eccf210bba3fb15361a1a7066bd7 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 10:23:57 +0200 Subject: [PATCH] mail page imap connection mime 5 bis rest 16 login page 27 --- components/email.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/email.tsx b/components/email.tsx index 220cf38..edffb35 100644 --- a/components/email.tsx +++ b/components/email.tsx @@ -41,6 +41,8 @@ export function Email() { const response = await fetch('/api/mail'); const data = await response.json(); + console.log('Raw API response:', data); // Debug log + if (!response.ok) { if (response.status === 401) { signIn(); @@ -49,8 +51,14 @@ export function Email() { throw new Error(data.error || 'Failed to fetch emails'); } - // Transform the raw emails into the expected format - const transformedEmails = (data || []).map((email: any) => ({ + // Make sure we're accessing the emails array from the response + if (!Array.isArray(data.emails)) { + console.error('Expected emails array in response, got:', data); + throw new Error('Invalid response format: emails array not found'); + } + + // Transform the emails array into the expected format + const transformedEmails = data.emails.map((email: any) => ({ id: String(email.id), subject: email.subject || '(No subject)', sender: { @@ -61,6 +69,8 @@ export function Email() { isUnread: !email.read })); + console.log('Transformed emails:', transformedEmails); // Debug log + setEmails(transformedEmails); setMailUrl(data.mailUrl); setError(null);