import { NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/app/api/auth/[...nextauth]/route'; import { prisma } from '@/lib/prisma'; export async function GET(request: Request) { try { // Verify user is authenticated const session = await getServerSession(authOptions); if (!session?.user?.id) { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ); } // Get credentials from database const credentials = await prisma.mailCredentials.findUnique({ where: { userId: session.user.id } }); if (!credentials) { return NextResponse.json( { error: 'No mail credentials found', credentials: null }, { status: 404 } ); } // Return only what's needed (especially the email) return NextResponse.json({ credentials: { email: credentials.email, host: credentials.host, port: credentials.port } }); } catch (error) { console.error('Error fetching credentials:', error); return NextResponse.json( { error: 'Failed to fetch credentials' }, { status: 500 } ); } }