diff --git a/src/core/service/user.service.ts b/src/core/service/user.service.ts index 17984dc..89364c8 100644 --- a/src/core/service/user.service.ts +++ b/src/core/service/user.service.ts @@ -26,24 +26,28 @@ export class UserService { } async createInitialUser() { - const existingUser = await this.userRepository.findOne({ - where: { username: 'admin' }, - }); - if (!existingUser) { - const salt = await bcrypt.genSalt(); - const encryptedPassword = await bcrypt.hash('admin123', salt); - - const user = this.userRepository.create({ - username: 'admin', - encryptedPassword, - locked: false, - enabled: true, + try { + const existingUser = await this.userRepository.findOne({ + where: { username: 'admin' }, }); + if (!existingUser) { + const salt = await bcrypt.genSalt(); + const encryptedPassword = await bcrypt.hash('admin123', salt); - await this.userRepository.save(user); - console.log('Initial admin user created'); - } else { - console.log('Admin user already exists'); + const user = this.userRepository.create({ + username: 'admin', + encryptedPassword, + locked: false, + enabled: true, + }); + + await this.userRepository.save(user); + console.log('Initial admin user created'); + } else { + console.log('Admin user already exists'); + } + } catch (error) { + console.log('Error creating initial user', error); } } }