spb/groupe-ka Public
Groupe KA — site du holding + KA ID (compte unique & SSO des 7 plateformes). Next.js 16, SQLite, Google & Apple login.
TypeScript 89.7%
CSS 5.8%
HTML 4.4%
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2// Profil enrichi du KA ID — saisi ICI, au hub, et affiché par toutes les3// plateformes du groupe (via /api/sso/profile). POST = mise à jour.4import { NextRequest, NextResponse } from "next/server";5import { db, SOCIAL_KEYS } from "@/lib/db";6import { getSessionUser } from "@/lib/auth";78const clip = (v: unknown, max: number): string =>9 typeof v === "string" ? v.trim().slice(0, max) : "";1011export async function POST(req: NextRequest) {12 const user = await getSessionUser();13 if (!user)14 return NextResponse.json({ error: "Non connecté." }, { status: 401 });1516 const body = (await req.json().catch(() => ({}))) as Record<string, unknown>;1718 const name = clip(body.name, 80);19 const bio = clip(body.bio, 280);20 const city = clip(body.city, 60);21 const phone = clip(body.phone, 40);22 const website = clip(body.website, 300);23 const jobTitle = clip(body.job_title, 80);24 const company = clip(body.company, 80);25 const birthDate = clip(body.birth_date, 10);2627 if (birthDate && !/^\d{4}-\d{2}-\d{2}$/.test(birthDate))28 return NextResponse.json(29 { error: "Date de naissance invalide (AAAA-MM-JJ)." },30 { status: 400 },31 );32 if (website && !/^https?:\/\//i.test(website) && website.length > 0)33 return NextResponse.json(34 { error: "Le site web doit commencer par http(s)://" },35 { status: 400 },36 );3738 const socialsIn = (body.socials ?? {}) as Record<string, unknown>;39 const socials: Record<string, string> = {};40 for (const k of SOCIAL_KEYS) {41 const v = clip(socialsIn[k], 200);42 if (v) socials[k] = v;43 }4445 db.prepare(46 `UPDATE users SET47 name = CASE WHEN ? != '' THEN ? ELSE name END,48 bio = ?, city = ?, phone = ?, website = ?,49 job_title = ?, company = ?, birth_date = ?, socials = ?50 WHERE id = ?`,51 ).run(52 name,53 name,54 bio,55 city,56 phone,57 website,58 jobTitle,59 company,60 birthDate,61 JSON.stringify(socials),62 user.id,63 );64 return NextResponse.json({ ok: true });65}66