Checkpoint: Migration complète vers authentification locale (JWT + bcrypt) : schéma DB (10 tables), routes tRPC (auth, users, etablissements, inventaire, capex, opex, parametres), page de login avec branding Itinova/Santinova, protection des routes, onglets Établissements et Utilisateurs branchés sur tRPC, import inventaire/établissements/utilisateurs via tRPC, 14 tests Vitest passants.
This commit is contained in:
60
scripts/seed-admin.mjs
Normal file
60
scripts/seed-admin.mjs
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Seed — Crée le compte administrateur par défaut Itinova
|
||||
* Login : adminItinova
|
||||
* Mot de passe : Itinova69!
|
||||
* Profil : admin
|
||||
*/
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import mysql from "mysql2/promise";
|
||||
import bcrypt from "bcryptjs";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const DATABASE_URL = process.env.DATABASE_URL;
|
||||
if (!DATABASE_URL) {
|
||||
console.error("DATABASE_URL not set");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const connection = await mysql.createConnection(DATABASE_URL);
|
||||
const db = drizzle(connection);
|
||||
|
||||
const ADMIN_LOGIN = "adminItinova";
|
||||
const ADMIN_PASSWORD = "Itinova69!";
|
||||
|
||||
try {
|
||||
// Vérifier si l'admin existe déjà
|
||||
const [existing] = await connection.execute(
|
||||
"SELECT id FROM users WHERE login = ?",
|
||||
[ADMIN_LOGIN]
|
||||
);
|
||||
|
||||
if (existing.length > 0) {
|
||||
console.log(`✓ Le compte administrateur "${ADMIN_LOGIN}" existe déjà.`);
|
||||
} else {
|
||||
const passwordHash = await bcrypt.hash(ADMIN_PASSWORD, 10);
|
||||
await connection.execute(
|
||||
`INSERT INTO users (login, email, passwordHash, firstName, lastName, role, isActive, createdAt, updatedAt)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), NOW())`,
|
||||
[
|
||||
ADMIN_LOGIN,
|
||||
"adminItinova@santinova-soft.org",
|
||||
passwordHash,
|
||||
"Admin",
|
||||
"Itinova",
|
||||
"admin",
|
||||
1,
|
||||
]
|
||||
);
|
||||
console.log(`✓ Compte administrateur "${ADMIN_LOGIN}" créé avec succès.`);
|
||||
console.log(` Login : ${ADMIN_LOGIN}`);
|
||||
console.log(` Password : ${ADMIN_PASSWORD}`);
|
||||
console.log(` Profil : admin`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du seed :", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await connection.end();
|
||||
}
|
||||
Reference in New Issue
Block a user