panel 2 courier api restore

This commit is contained in:
alma 2025-04-25 19:34:47 +02:00
parent d4652d500f
commit 6c5baa6f40

View File

@ -1681,37 +1681,40 @@ export default function CourrierPage() {
}; };
}, [accounts, loading]); }, [accounts, loading]);
// Add a function to fetch the IMAP credentials directly // Add a new function to fetch the IMAP credentials email
const fetchMailCredentials = async () => { const fetchImapCredentials = async () => {
try { try {
const response = await fetch('/api/courrier'); const response = await fetch('/api/courrier/credentials');
if (!response.ok) { if (!response.ok) {
console.error('Failed to fetch IMAP credentials', response.status);
return; return;
} }
const data = await response.json(); const data = await response.json();
// If we have email credentials, update the account // If we have credentials with an email, update the account
if (data && data.email) { if (data && data.credentials && data.credentials.email) {
console.log('Got IMAP email:', data.email); console.log('Got IMAP credentials email:', data.credentials.email);
setAccounts(prev => prev.map(account => setAccounts(prev => prev.map(account =>
account.id === 1 account.id === 1
? { ? {
...account, ...account,
name: data.email, name: data.credentials.email,
email: data.email email: data.credentials.email
} }
: account : account
)); ));
} else {
console.warn('No IMAP email found in credentials');
} }
} catch (error) { } catch (error) {
console.error('Error fetching mail credentials:', error); console.error('Error fetching IMAP credentials:', error);
} }
}; };
// Call it once on component mount // Call it once on component mount
useEffect(() => { useEffect(() => {
fetchMailCredentials(); fetchImapCredentials();
}, []); }, []);
if (error) { if (error) {