Checkpoint: Le champ de connexion accepte maintenant un identifiant (ex: adminItinova) ou une adresse e-mail. Le backend recherche dans les deux cas. Le label et le placeholder ont été mis à jour.

This commit is contained in:
Manus
2026-03-20 08:44:29 -04:00
parent e9a8ae9016
commit cab8629125
5 changed files with 39 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import bcrypt from "bcryptjs";
import { getDb } from "./db";
import { localUsers } from "../drizzle/schema";
import { eq } from "drizzle-orm";
import { eq, or } from "drizzle-orm";
import { SignJWT, jwtVerify } from "jose";
import { ENV } from "./_core/env";
@@ -41,10 +41,17 @@ export async function loginLocalUser(email: string, password: string) {
const db = await getDb();
if (!db) throw new Error("Base de données indisponible");
// Recherche par e-mail (insensible à la casse) OU par identifiant exact
const identifier = email.trim();
const users = await db
.select()
.from(localUsers)
.where(eq(localUsers.email, email.toLowerCase().trim()))
.where(
or(
eq(localUsers.email, identifier.toLowerCase()),
eq(localUsers.email, identifier)
)
)
.limit(1);
const user = users[0];