From fd9f93905d31b12ff1faf932a6771d219929d85b Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 25 Apr 2025 20:02:17 +0200 Subject: [PATCH] panel 2 courier api restore --- app/api/courrier/credentials/route.ts | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/api/courrier/credentials/route.ts diff --git a/app/api/courrier/credentials/route.ts b/app/api/courrier/credentials/route.ts new file mode 100644 index 00000000..9affd60d --- /dev/null +++ b/app/api/courrier/credentials/route.ts @@ -0,0 +1,44 @@ +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 } + ); + } +} \ No newline at end of file