Fix initial user creating

This commit is contained in:
2026-04-29 00:55:00 +03:00
parent 3565390a49
commit 66c84ecdeb
16 changed files with 267 additions and 35 deletions

View File

@@ -1,29 +1,25 @@
const bcrypt = require('bcrypt');
const pool = require('../src/config/database');
const { ensureBootstrapAdmin, readBootstrapAdminConfig } = require('../src/utils/bootstrapAdmin');
async function createAdmin() {
const username = 'admin';
const password = 'admin123'; // Измените после первого входа!
const passwordHash = await bcrypt.hash(password, 10);
const config = readBootstrapAdminConfig();
try {
const result = await pool.query(`
INSERT INTO users (username, password_hash, full_name, email, role, is_active)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (username) DO UPDATE
SET password_hash = $2
RETURNING id, username, role
`, [username, passwordHash, 'Главный администратор', 'admin@polotsk-transit.local', 'admin', true]);
const result = await ensureBootstrapAdmin({
resetPassword: true,
createIfActiveAdminExists: true,
});
console.log('✅ Мастер-аккаунт создан:', result.rows[0]);
console.log('Username: admin');
console.log('Password: admin123');
console.log('⚠️ ОБЯЗАТЕЛЬНО смените пароль после первого входа!');
console.log('Master account is ready:', result.user);
console.log(`Username: ${config.username}`);
console.log(`Password: ${config.password}`);
console.log('Change this password after the first login.');
} catch (error) {
console.error('❌ Ошибка:', error);
console.error('Error:', error);
process.exitCode = 1;
} finally {
await pool.end();
}
}
createAdmin();
createAdmin();