Hello, I don't understand why my password is not hashed in database...
//Controller file
@Post()
async create(@Body() user: User): Promise<User> {
try {
return await this.userService.create(user);
} catch (error) {
throw new HttpException(
{
status: HttpStatus.INTERNAL_SERVER_ERROR,
error: error.detail.includes('email')
? "L'adresse mail est déjà utilisée"
: "Le nom d'utilisateur est déjà utilisé.",
},
HttpStatus.INTERNAL_SERVER_ERROR,
{
cause: error,
},
);
}
}
//Service file
async create(user: User): Promise<User> {
return await User.save(user);
}
//Entity file
@Column()
password: string;
@BeforeInsert()
async hashPassword() {
this.password = await bcrypt.hash(this.password, 10);
}