- Replace ADMIN_SECRET query param with proper Supabase auth + is_admin flag - Add admin layout with auth check (redirects non-admin to /) - Add AdminShell component with sidebar navigation (Dashboard, Candidatures, Cours) - Add admin dashboard with stats (candidatures, users, modules) - Add admin candidatures page with filters and approve/reject - Add admin course management page (create, edit, delete, publish/unpublish) - Add API routes: GET/POST /api/admin/modules, GET/PUT/DELETE /api/admin/modules/[id] - Add verifyAdmin() helper for API route protection - Update database types with is_admin on profiles https://claude.ai/code/session_01H2aRGDaKgarPvhay2HxN6Y
31 lines
889 B
TypeScript
31 lines
889 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { createAdminClient } from "@/lib/supabase/server";
|
|
import { verifyAdmin, isAdminError } from "@/lib/admin";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// POST /api/admin/candidatures/[id]/reject - Rejeter une candidature
|
|
export async function POST(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const auth = await verifyAdmin();
|
|
if (isAdminError(auth)) {
|
|
return NextResponse.json({ error: auth.error }, { status: auth.status });
|
|
}
|
|
|
|
const { id } = await params;
|
|
const supabase = createAdminClient();
|
|
|
|
const { error } = await supabase
|
|
.from("candidatures")
|
|
.update({ status: "rejected" } as never)
|
|
.eq("id", id);
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
}
|
|
|
|
return NextResponse.json({ success: true, message: "Candidature rejetée." });
|
|
}
|