diff --git a/src/app/api/create/[id]/route.ts b/src/app/api/create/[id]/route.ts new file mode 100644 index 0000000..88b588b --- /dev/null +++ b/src/app/api/create/[id]/route.ts @@ -0,0 +1,17 @@ +import { NextResponse } from "next/server"; +import { getCurrentUser } from "@/lib/session"; +import { getCreatedById } from "@/lib/createdLessons"; + +// Poll the status of a creation (owner or admin). +export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) { + const user = await getCurrentUser(); + if (!user) return NextResponse.json({ error: "Log in." }, { status: 401 }); + + const { id } = await ctx.params; + const row = getCreatedById(Number(id)); + if (!row) return NextResponse.json({ error: "Not found." }, { status: 404 }); + if (row.user_id !== user.id && user.role !== "admin") + return NextResponse.json({ error: "Not authorized." }, { status: 403 }); + + return NextResponse.json({ id: row.id, slug: row.slug, status: row.status, error: row.error, subject: row.subject }); +}