How can I save an encrypted password to MongoDB?
P.S. I'm a beginner developer and still learning how to use NestJS
If you are using TypeOrm there is a decorator name's @BeforeInsert()
@Entity("YourTable", { schema: "yourdb" })
export class YourTable {
   ...
   @BeforeInsert()
   async hashPassword() {
      this.password = await bcrypt.hash(this.password, Number(process.env.HASH_SALT));
   }
   ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With