|
|
@@ -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);
|
|
|
+
|
|
|
+ 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');
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
}
|