// Auteur : Simon-Pierre Boucher — contact@spboucher.ai // Définit (ou modifie) le type de compte du KA ID — obligatoire à la // création ; les comptes arrivés par Google le choisissent ici. import { NextRequest, NextResponse } from "next/server"; import { db } from "@/lib/db"; import { getSessionUser } from "@/lib/auth"; import { ROLES } from "@/lib/roles"; export async function POST(req: NextRequest) { const user = await getSessionUser(); if (!user) return NextResponse.json({ error: "Non connecté." }, { status: 401 }); const body = (await req.json().catch(() => ({}))) as { role?: string }; const role = body.role ?? ""; if (!ROLES[role]) return NextResponse.json( { error: "Type de compte invalide." }, { status: 400 }, ); db.prepare("UPDATE users SET role = ? WHERE id = ?").run(role, user.id); return NextResponse.json({ ok: true, role }); }