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