panel 2 courier api restore

This commit is contained in:
alma 2025-04-25 19:30:06 +02:00
parent ca93e4bc26
commit f3ed371b33

View File

@ -546,6 +546,25 @@ export default function CourrierPage() {
throw new Error(errorData.error || 'Failed to check credentials'); throw new Error(errorData.error || 'Failed to check credentials');
} }
try {
// Try to get user email from credentials
const credsData = await credResponse.json();
if (credsData.email) {
console.log('Got email from credentials:', credsData.email);
setAccounts(prev => prev.map(account =>
account.id === 1
? {
...account,
name: credsData.email,
email: credsData.email
}
: account
));
}
} catch (error) {
console.warn('Error getting email from credentials:', error);
}
// First do a quick request just for folders // First do a quick request just for folders
try { try {
const folderResponse = await fetch('/api/courrier?folder=INBOX&page=1&limit=1'); const folderResponse = await fetch('/api/courrier?folder=INBOX&page=1&limit=1');
@ -648,12 +667,16 @@ export default function CourrierPage() {
loadInitialData(); loadInitialData();
}, [router, currentView, page, emailsPerPage]); }, [router, currentView, page, emailsPerPage]);
// At the initialization, update the account with the email from session // Fix the type issue with the session email
useEffect(() => { useEffect(() => {
if (session?.user?.email) { if (session?.user?.email) {
setAccounts(prev => prev.map(account => setAccounts(prev => prev.map(account =>
account.id === 1 account.id === 1
? { ...account, name: session.user.email, email: session.user.email } ? {
...account,
name: session.user.email || 'Mail Account',
email: session.user.email || ''
}
: account : account
)); ));
} }