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 85.5%
HTML 8.9%
CSS 5.5%
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2import { NextRequest, NextResponse } from "next/server";3import { findUserByEmail, touchLastLogin } from "@/lib/db";4import {5 verifyPassword,6 mintSessionToken,7 SESSION_COOKIE,8 sessionCookieOptions,9} from "@/lib/auth";1011export async function POST(req: NextRequest) {12 let body: { email?: string; password?: string };13 try {14 body = await req.json();15 } catch {16 return NextResponse.json({ error: "Requête invalide." }, { status: 400 });17 }18 const email = (body.email ?? "").trim().toLowerCase();19 const password = body.password ?? "";2021 const user = findUserByEmail(email);22 if (!user || !user.password_hash) {23 return NextResponse.json(24 {25 error: user26 ? "Ce KA ID a été créé avec Google — utilisez « Continuer avec Google »."27 : "Courriel ou mot de passe incorrect.",28 },29 { status: 401 },30 );31 }32 if (!verifyPassword(password, user.password_hash))33 return NextResponse.json(34 { error: "Courriel ou mot de passe incorrect." },35 { status: 401 },36 );3738 touchLastLogin(user.id);39 const res = NextResponse.json({ ok: true });40 res.cookies.set(41 SESSION_COOKIE,42 await mintSessionToken(user.id),43 sessionCookieOptions,44 );45 return res;46}47