0.1.8 • Published 2 years ago

nestjs-hash v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

License

MIT licensed.

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago