Initial commit — Умный Байт landing

This commit is contained in:
2026-05-13 09:32:45 +03:00
commit 9e21350def
37 changed files with 1950 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import { queryOne, query } from '../db/pool.js';
import { hashPassword } from '../auth/jwt.js';
export async function initFirstAdmin(): Promise<void> {
const existing = await queryOne<{ count: string }>(
`SELECT COUNT(*)::text AS count FROM admin_users`
);
const count = parseInt(existing?.count || '0', 10);
if (count > 0) {
return;
}
const password = process.env.ADMIN_INITIAL_PASSWORD || 'admin';
const hash = await hashPassword(password);
await query(
`INSERT INTO admin_users (login, password_hash) VALUES ($1, $2)`,
['admin', hash]
);
console.log('[init-admin] Создан первый админ: admin');
if (password === 'admin') {
console.warn(
'[init-admin] ВНИМАНИЕ: используется дефолтный пароль "admin". Смените его сразу!'
);
}
}