implement jwt auth

This commit is contained in:
Philipinho
2023-08-05 16:58:34 +01:00
parent cebad0e0a5
commit 6e3ba20fcf
21 changed files with 744 additions and 46 deletions
@@ -1,10 +1,12 @@
import {
BeforeInsert,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import * as bcrypt from 'bcrypt';
@Entity('users')
export class User {
@@ -46,4 +48,15 @@ export class User {
@UpdateDateColumn()
updatedAt: Date;
toJSON() {
delete this.password;
return this;
}
@BeforeInsert()
async hashPassword() {
const saltRounds = 12;
this.password = await bcrypt.hash(this.password, saltRounds);
}
}