diff --git a/app/agenda/page.tsx b/app/agenda/page.tsx index aa5e36e..2876c8c 100644 --- a/app/agenda/page.tsx +++ b/app/agenda/page.tsx @@ -178,9 +178,7 @@ export default async function CalendarPage() { // For each Infomaniak account, ensure there's a synced calendar // Skip if no Infomaniak accounts exist (user may only have Microsoft accounts) if (infomaniakAccounts.length > 0) { - console.log(`[AGENDA] Processing ${infomaniakAccounts.length} Infomaniak account(s)`); for (const account of infomaniakAccounts) { - console.log(`[AGENDA] Processing Infomaniak account: ${account.email}, hasPassword: ${!!account.password}, passwordLength: ${account.password?.length || 0}`); // Check if a calendar sync already exists for this account (enabled or disabled) // This prevents creating duplicate calendars for the same account let existingSync = await prisma.calendarSync.findFirst({ @@ -341,21 +339,11 @@ export default async function CalendarPage() { // No sync exists for this account - try to discover and create calendar // Only create calendar if discovery succeeds try { - // Verify password is available - if (!account.password) { - console.log(`[AGENDA] Skipping Infomaniak account ${account.email} - no password available`); - continue; - } - - console.log(`[AGENDA] Attempting to discover calendars for Infomaniak account ${account.email} (password length: ${account.password.length})`); - const { discoverInfomaniakCalendars } = await import('@/lib/services/caldav-sync'); const externalCalendars = await discoverInfomaniakCalendars( account.email, - account.password + account.password! ); - - console.log(`[AGENDA] Discovered ${externalCalendars.length} calendars for Infomaniak account ${account.email}`); if (externalCalendars.length > 0) { // Use the first calendar (usually the main calendar) diff --git a/lib/services/caldav-sync.ts b/lib/services/caldav-sync.ts index ba2405d..c3bbbd6 100644 --- a/lib/services/caldav-sync.ts +++ b/lib/services/caldav-sync.ts @@ -27,19 +27,8 @@ export async function getInfomaniakCalDAVClient( password: string ): Promise { // Infomaniak CalDAV base URL (from Infomaniak sync assistant) - // The actual CalDAV endpoint is at /caldav path - const baseUrl = 'https://sync.infomaniak.com/caldav'; - - if (!password || password.trim() === '') { - throw new Error('Password is required for Infomaniak CalDAV authentication'); - } - - logger.debug('Creating Infomaniak CalDAV client', { - email, - baseUrl, - hasPassword: !!password, - passwordLength: password.length, - }); + // Base URL is https://sync.infomaniak.com, CalDAV endpoint is accessed via /caldav path + const baseUrl = 'https://sync.infomaniak.com'; const client = createClient(baseUrl, { username: email, @@ -57,49 +46,10 @@ export async function discoverInfomaniakCalendars( password: string ): Promise { try { - logger.debug('Starting Infomaniak calendar discovery', { - email, - hasPassword: !!password, - passwordLength: password?.length || 0, - }); - const client = await getInfomaniakCalDAVClient(email, password); - logger.debug('CalDAV client created, attempting to list directory contents'); - - // List all calendars using PROPFIND on root - let items; - try { - items = await client.getDirectoryContents('/'); - logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`); - } catch (dirError: any) { - // Log more details about the error - const errorDetails: any = { - email, - error: dirError?.message || String(dirError), - status: dirError?.status, - statusText: dirError?.statusText, - }; - - // Try to extract more details from the error - if (dirError?.response) { - errorDetails.responseStatus = dirError.response.status; - errorDetails.responseStatusText = dirError.response.statusText; - errorDetails.responseHeaders = dirError.response.headers; - } - - // Check if it's a 401 error specifically - if (dirError?.status === 401 || dirError?.response?.status === 401) { - logger.error('CalDAV authentication failed (401 Unauthorized)', { - ...errorDetails, - hint: 'This usually means: 1) Password is incorrect, 2) Password has changed, 3) 2FA is enabled and requires an app-specific password, 4) Account credentials are invalid', - }); - } else { - logger.error('Error listing directory contents', errorDetails); - } - - throw dirError; - } + // List all calendars using PROPFIND on /caldav path + const items = await client.getDirectoryContents('/caldav'); const calendars: CalDAVCalendar[] = [];