mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Creates an admin user with default credentials ('admin'/'admin') if one does not exist upon server startup, ensuring initial access for new deployments.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/COxOmlM
31 lines
948 B
TypeScript
31 lines
948 B
TypeScript
import { storage } from "./storage";
|
|
import bcrypt from "bcrypt";
|
|
|
|
export async function ensureAdminUserExists() {
|
|
try {
|
|
const adminUser = await storage.getUserByUsername("admin");
|
|
|
|
if (!adminUser) {
|
|
console.log("🔧 Création de l'utilisateur admin par défaut...");
|
|
|
|
const hashedPassword = await bcrypt.hash("admin", 10);
|
|
|
|
await storage.createUser({
|
|
username: "admin",
|
|
password: hashedPassword,
|
|
role: "admin",
|
|
});
|
|
|
|
console.log("✅ Utilisateur admin créé avec succès");
|
|
console.log(" Username: admin");
|
|
console.log(" Password: admin");
|
|
console.log(" ⚠️ IMPORTANT: Changez ce mot de passe immédiatement !");
|
|
} else {
|
|
console.log("✓ Utilisateur admin existe déjà");
|
|
}
|
|
} catch (error) {
|
|
console.error("❌ Erreur lors de la vérification/création de l'utilisateur admin:", error);
|
|
throw error;
|
|
}
|
|
}
|