courrier multi account
This commit is contained in:
parent
b34bdee164
commit
184d5180fa
51
app/api/courrier/account-list/route.ts
Normal file
51
app/api/courrier/account-list/route.ts
Normal file
@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user