mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
35 lines
982 B
TypeScript
35 lines
982 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { db } from '@/lib/db';
|
|
import { auth } from '@/lib/auth';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const session = await auth();
|
|
if (!session?.user?.isAdmin) {
|
|
return new NextResponse('Unauthorized', { status: 403 });
|
|
}
|
|
|
|
const users = await db.user.findMany({
|
|
orderBy: { createdAt: 'desc' },
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
createdAt: true,
|
|
_count: {
|
|
select: {
|
|
ownedWorkspaces: true,
|
|
projects: true,
|
|
comments: true,
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return NextResponse.json({ users });
|
|
} catch (error) {
|
|
console.error('[ADMIN_USERS_GET]', error);
|
|
return new NextResponse('Internal Error', { status: 500 });
|
|
}
|
|
}
|