import { NextResponse, NextRequest } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/app/api/auth/[...nextauth]/route'; export async function GET(req: NextRequest) { try { const session = await getServerSession(authOptions); if (!session?.user?.email) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const nextcloudUrl = process.env.NEXTCLOUD_URL; if (!nextcloudUrl) { console.error('Missing Nextcloud URL'); return NextResponse.json( { error: 'Nextcloud configuration is missing' }, { status: 500 } ); } // Return the Nextcloud Mail iframe URL with an empty emails array return NextResponse.json({ emails: [], // Initialize with empty array mailUrl: `${nextcloudUrl}/apps/mail/box/unified` }); } catch (error) { console.error('Error getting Mail URL:', error); return NextResponse.json( { error: "L'application Mail n'est pas disponible sur Nextcloud. Veuillez contacter votre administrateur.", emails: [] // Initialize with empty array even in error case }, { status: 404 } ); } }