Files
sfera/scripts/create-admin.mjs

43 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcryptjs'
const prisma = new PrismaClient()
async function createAdmin() {
try {
console.log('🔐 Создание администратора...')
// Генерируем хеш пароля
const password = 'admin123' // Временный пароль
const hashedPassword = await bcrypt.hash(password, 12)
// Создаем администратора
const admin = await prisma.admin.create({
data: {
username: 'admin',
password: hashedPassword,
email: 'admin@sferav.com',
isActive: true
}
})
console.log('✅ Администратор создан:')
console.log(` Логин: ${admin.username}`)
console.log(` Пароль: ${password}`)
console.log(` Email: ${admin.email}`)
console.log(` ID: ${admin.id}`)
console.log('\n⚠ Обязательно смените пароль после первого входа!')
} catch (error) {
if (error.code === 'P2002') {
console.log('❌ Администратор с таким логином уже существует')
} else {
console.error('❌ Ошибка создания администратора:', error)
}
} finally {
await prisma.$disconnect()
}
}
createAdmin()