Files
Atlas/app/api/projects/route.ts
2025-11-12 20:21:32 +01:00

28 lines
732 B
TypeScript

import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
export async function GET() {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const projects = await prisma.project.findMany({
where: {
active: true,
},
orderBy: {
name: 'asc',
},
});
return NextResponse.json({ projects });
} catch (error) {
console.error('Error fetching projects:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}