fix: 错误捕捉
This commit is contained in:
1 parent
2ca39b3777
commit
4742e2013d
1 file changed
+20
-16
@@ -26,24 +26,28 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createInitialUser() {
|
async createInitialUser() {
|
||||||
const existingUser = await this.userRepository.findOne({
|
try {
|
||||||
where: { username: 'admin' },
|
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,
|
|
||||||
});
|
});
|
||||||
|
if (!existingUser) {
|
||||||
|
const salt = await bcrypt.genSalt();
|
||||||
|
const encryptedPassword = await bcrypt.hash('admin123', salt);
|
||||||
|
|
||||||
await this.userRepository.save(user);
|
const user = this.userRepository.create({
|
||||||
console.log('Initial admin user created');
|
username: 'admin',
|
||||||
} else {
|
encryptedPassword,
|
||||||
console.log('Admin user already exists');
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user