fix: hardcode credentials

This commit is contained in:
Den Piligrim
2026-02-06 12:42:25 +03:00
parent 1b2112e6d9
commit 460e31260e
3 changed files with 20 additions and 5 deletions
+7 -3
View File
@@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import * as bcrypt from 'bcrypt';
import { Setting } from '../settings/entities/setting.entity';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class AuthService {
@@ -13,6 +14,7 @@ export class AuthService {
@InjectRepository(Setting)
private settingsRepo: Repository<Setting>,
private jwtService: JwtService,
private configService: ConfigService,
) {}
async validateUser(login: string, pass: string): Promise<any> {
@@ -85,12 +87,14 @@ export class AuthService {
const login = await this.settingsRepo.findOne({ where: { key: 'admin_login' } });
if (!login) {
this.logger.log('Инициализация администратора (admin / admin)...');
this.logger.log('Инициализация администратора...');
const envLogin = this.configService.get<string>('ADMIN_LOGIN') || 'admin';
const envPass = this.configService.get<string>('ADMIN_PASSWORD') || 'admin';
const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: 'admin' });
const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: envLogin });
await this.settingsRepo.save(loginSetting);
const hash = await bcrypt.hash('admin', 10);
const hash = await bcrypt.hash(envPass, 10);
const passSetting = this.settingsRepo.create({ key: 'admin_password', value: hash });
await this.settingsRepo.save(passSetting);