From 45194e6a90e656a60dd2efc5b4aa82d13019acf8 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 14 Jan 2026 20:30:00 +0100 Subject: [PATCH] Agenda refactor --- app/agenda/page.tsx | 12 +++++++++++- lib/services/caldav-sync.ts | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/agenda/page.tsx b/app/agenda/page.tsx index 7a2dbd5..aa5e36e 100644 --- a/app/agenda/page.tsx +++ b/app/agenda/page.tsx @@ -178,7 +178,9 @@ 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({ @@ -339,10 +341,18 @@ 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}`); diff --git a/lib/services/caldav-sync.ts b/lib/services/caldav-sync.ts index 687e224..0e093b7 100644 --- a/lib/services/caldav-sync.ts +++ b/lib/services/caldav-sync.ts @@ -30,6 +30,17 @@ export async function getInfomaniakCalDAVClient( // 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, + }); + const client = createClient(baseUrl, { username: email, password: password, @@ -46,11 +57,21 @@ 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 const items = await client.getDirectoryContents('/'); + logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`); + const calendars: CalDAVCalendar[] = []; for (const item of items) {