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));
}
...
}