Let's have simplified TypeORM entity User
:
@Entity()
export class User extends BaseDatabaseEntity {
@Column({
length: 255,
})
public firstName!: string;
@Column({ length: 60 })
@Exclude()
public password: string;
@BeforeUpdate()
@BeforeInsert()
private hashPassword(): void {
const tmpPassword = hashSync(
this.password + 'config.auth.password.secret',
genSaltSync(),
);
this.password = tmpPassword;
}
}
}
I need to replace config.auth.password.secret
with NestJS's config (namespace from ConfigService):
export default registerAs('app', () => {
return {
password: {
secret: process.env.AUTH_PASSWORD_SECRET,
}
};
});
, but entities are not part of NestJS structure so I cannot just inject it as usual.
How to achieve NestJS configs in TypeORM entities?