From 184d5180fa8a56704e4a3814ecf035a862707f13 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 17:15:54 +0200 Subject: [PATCH] courrier multi account --- app/api/courrier/account-list/route.ts | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/api/courrier/account-list/route.ts diff --git a/app/api/courrier/account-list/route.ts b/app/api/courrier/account-list/route.ts new file mode 100644 index 00000000..7a141eb9 --- /dev/null +++ b/app/api/courrier/account-list/route.ts @@ -0,0 +1,51 @@ +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 { + // Authenticate user + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json( + { error: 'Unauthorized' }, + { status: 401 } + ); + } + + // Get all email accounts for this user + const accounts = await prisma.mailCredentials.findMany({ + where: { userId: session.user.id }, + select: { + id: true, + email: true, + host: true, + port: true, + secure: true, + display_name: true, + color: true, + smtp_host: true, + smtp_port: true, + smtp_secure: true, + createdAt: true, + updatedAt: true + } + }); + + // Never return passwords + return NextResponse.json({ + success: true, + accounts + }); + } catch (error) { + console.error('Error fetching email accounts:', error); + return NextResponse.json( + { + error: 'Failed to fetch email accounts', + details: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ); + } +} \ No newline at end of file