import { NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from "@/app/api/auth/options"; import { prisma } from '@/lib/prisma'; export async function GET(request: Request) { try { // Authenticate user const session = await getServerSession(authOptions); if (!session?.user?.id) { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ); } // Get accountId from query params const { searchParams } = new URL(request.url); const accountId = searchParams.get('accountId'); if (!accountId) { return NextResponse.json( { error: 'Account ID is required' }, { status: 400 } ); } // Get account details from database, including connection details const account = await prisma.mailCredentials.findFirst({ where: { id: accountId, userId: session.user.id }, select: { id: true, email: true, host: true, port: true, secure: true, display_name: true, color: true, // Don't include the password in the response } }); if (!account) { return NextResponse.json( { error: 'Account not found' }, { status: 404 } ); } return NextResponse.json(account); } catch (error) { console.error('Error fetching account details:', error); return NextResponse.json( { error: 'Failed to fetch account details', details: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ); } }