A progressive Node.js framework for building efficient and scalable server-side applications.
Hashing library for NestJS.
$ npm install nestjs-hash
or
$ yarn add nestjs-hash
Using with native hash
import { HashModule } from 'nestjs-hash';
@Module({
imports: [HashModule.forRoot({ type: 'sha256' })],
})
export default UsersModule;
or external library hash
import { HashModule } from 'nestjs-hash';
@Module({
imports: [HashModule.forRoot({ type: 'bcrypt', rounds: 16 })],
})
export default UsersModule;
Attention to use bcrypt or more libraries you need to add them as dependencies to your project.
- bcrypt
$ npm install bcrypt
- argon2
$ npm install argon2
2 - second uses dependency injection to add the hash service to your service
@Injectable()
export class UsersService() {
constructor(
private readonly hashService: HashService,
private readonly usersRepository: UsersRepository
) {}
public async createUser(data) {
const passwordHash = await this.hashService.hash(data.password);
const user = await this.usersRepository.create({
...data,
password: passwordHash
});
return user;
}
};
Created with more love by Arthur Reis