mail page imap connection mime 5 bis rest 16 login page 28
This commit is contained in:
parent
a7d06570d6
commit
c4355749ce
@ -39,26 +39,23 @@ export function Email() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail');
|
const response = await fetch('/api/mail');
|
||||||
const data = await response.json();
|
const rawData = await response.json();
|
||||||
|
|
||||||
console.log('Raw API response:', data); // Debug log
|
console.log('Raw API response:', rawData);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
signIn();
|
signIn();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(data.error || 'Failed to fetch emails');
|
throw new Error(rawData.error || 'Failed to fetch emails');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we're accessing the emails array from the response
|
// Handle both array and object responses
|
||||||
if (!Array.isArray(data.emails)) {
|
const emailsArray = Array.isArray(rawData) ? rawData : (rawData.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
|
// Transform the emails array into the expected format
|
||||||
const transformedEmails = data.emails.map((email: any) => ({
|
const transformedEmails = emailsArray.map((email: any) => ({
|
||||||
id: String(email.id),
|
id: String(email.id),
|
||||||
subject: email.subject || '(No subject)',
|
subject: email.subject || '(No subject)',
|
||||||
sender: {
|
sender: {
|
||||||
@ -69,10 +66,10 @@ export function Email() {
|
|||||||
isUnread: !email.read
|
isUnread: !email.read
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Transformed emails:', transformedEmails); // Debug log
|
console.log('Transformed emails:', transformedEmails);
|
||||||
|
|
||||||
setEmails(transformedEmails);
|
setEmails(transformedEmails);
|
||||||
setMailUrl(data.mailUrl);
|
setMailUrl(rawData.mailUrl || 'https://espace.slm-lab.net/apps/mail/'); // Fallback URL
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error fetching emails:', err);
|
console.error('Error fetching emails:', err);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user