33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
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
|
|
return NextResponse.json({
|
|
url: `${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." },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
}
|