nestjs-hash
v0.1.8
Published
Hashing library for NestJS
Downloads
81
Maintainers
Readme
Description
Hashing library for NestJS.
Installation
$ npm install nestjs-hash
or
$ yarn add nestjs-hash
Hou to use
1 - first add hash module in import for your module
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;
}
};
Author
Created with more love by Arthur Reis