diff --git a/hooks/use-courrier.ts b/hooks/use-courrier.ts index dcdf4496..69675a85 100644 --- a/hooks/use-courrier.ts +++ b/hooks/use-courrier.ts @@ -218,14 +218,15 @@ export const useCourrier = () => { setIsLoading(false); // Still refresh in background for fresh data - // CRITICAL FIX: Use the same effective account ID for background refresh - console.log(`Starting background refresh with folder ${currentFolder}, account ${effectiveAccountId}`); + // CRITICAL FIX: Use the normalized folder and explicit account ID together for background refresh + // This prevents issues with account switching where the wrong folder prefix remains + console.log(`Starting background refresh with normalized folder=${normalizedFolder}, account=${effectiveAccountId}`); refreshEmailsInBackground( session.user.id, - currentFolder, + normalizedFolder, // CRITICAL FIX: Use the normalized folder WITHOUT prefix currentRequestPage, perPage, - effectiveAccountId // Always use the effective account ID + effectiveAccountId // Always pass the effective account ID explicitly ).catch(err => { console.error('Background refresh error:', err); });