#hash password

6 messages · Page 1 of 1 (latest)

vast oar
#

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);
  }
neat latch
vast oar
amber ridge
#

Hi sir, can I ask if @BeforeSave and @BeforeInsert are custom decorators?