panel 2 courier api restore

This commit is contained in:
alma 2025-04-25 20:02:17 +02:00
parent 6c5baa6f40
commit fd9f93905d

View File

@ -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 }
);
}
}