2025-09-09 00:15:08 +00:00
|
|
|
export const runtime = 'nodejs'
|
|
|
|
|
import { NextResponse } from 'next/server';
|
|
|
|
|
import { auth } from '@/auth';
|
|
|
|
|
import { PrismaClient } from '@/app/generated/prisma';
|
|
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
|
const session = await auth();
|
2025-09-10 04:31:53 +00:00
|
|
|
if (!session?.user?.email) {
|
2025-09-09 00:15:08 +00:00
|
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
|
|
|
}
|
2025-09-10 04:31:53 +00:00
|
|
|
const email = session.user.email as string;
|
2025-09-09 00:15:08 +00:00
|
|
|
|
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
try {
|
2025-09-10 04:31:53 +00:00
|
|
|
let rows;
|
2025-09-09 00:15:08 +00:00
|
|
|
if (email === 'wsx204@naver.com') {
|
2025-09-10 04:31:53 +00:00
|
|
|
// 관리자: 전체 핸들
|
|
|
|
|
rows = await prisma.handle.findMany({
|
2025-09-09 00:15:08 +00:00
|
|
|
orderBy: { handle: 'asc' },
|
2025-09-10 04:31:53 +00:00
|
|
|
select: { id: true, handle: true, avatar: true },
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 일반 사용자: 자신의 핸들만
|
|
|
|
|
rows = await prisma.handle.findMany({
|
|
|
|
|
where: { users: { some: { email } } },
|
|
|
|
|
orderBy: { handle: 'asc' },
|
|
|
|
|
select: { id: true, handle: true, avatar: true },
|
2025-09-09 00:15:08 +00:00
|
|
|
});
|
|
|
|
|
}
|
2025-09-10 04:31:53 +00:00
|
|
|
const items = rows.map(h => ({
|
2025-09-09 00:15:08 +00:00
|
|
|
id: h.id,
|
|
|
|
|
handle: h.handle,
|
|
|
|
|
createtime: new Date().toISOString(),
|
|
|
|
|
is_approved: false,
|
|
|
|
|
icon: h.avatar,
|
|
|
|
|
}));
|
|
|
|
|
return NextResponse.json({ items });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('list_channel 오류:', e);
|
|
|
|
|
return NextResponse.json({ error: '조회 실패' }, { status: 500 });
|
|
|
|
|
} finally {
|
|
|
|
|
await prisma.$disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|