Allow admin password to be changed and retained without resets

Modify production logic to prevent forced admin password resets on updates, allowing users to set and keep their own passwords unless explicitly overridden by an environment variable.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/kdCs97W
This commit is contained in:
michaelschal committed 2025-08-12 08:18:45 +00:00
1 parent 8e6f59e88a
commit 461290a4f8
2 files changed
+215 -17

No files matched your search

+16 -17
View File
@@ -110,23 +110,22 @@ async function createDefaultAdminUser() {
passwordFormat: existingAdmin.password ? 'present' : 'missing'
});
// Test if current password works with 'admin'
if (existingAdmin.password) {
const testLogin = await comparePasswords('admin', existingAdmin.password);
if (!testLogin) {
console.log('🔄 Admin password incompatible with current system, forcing reset...');
try {
const newHashedPassword = await hashPassword('admin');
await storage.updateUser(existingAdmin.id, {
password: newHashedPassword,
passwordChanged: false
});
console.log('✅ Admin password force-reset to: admin/admin');
} catch (error) {
console.error('❌ Failed to reset admin password:', (error as Error).message);
}
} else {
console.log('✅ Admin password works with current system');
// Ne plus forcer la réinitialisation du mot de passe admin
// L'admin peut maintenant changer son mot de passe et il sera conservé
console.log('✅ Admin user exists, preserving current password');
// Seulement réinitialiser si explicitement demandé via FORCE_ADMIN_RESET
if (process.env.FORCE_ADMIN_RESET === 'true') {
console.log('🔄 FORCE_ADMIN_RESET env var set, resetting admin password...');
try {
const newHashedPassword = await hashPassword('admin');
await storage.updateUser(existingAdmin.id, {
password: newHashedPassword,
passwordChanged: false
});
console.log('✅ Admin password manually reset to: admin/admin');
} catch (error) {
console.error('❌ Failed to reset admin password:', (error as Error).message);
}
}
}