Crypto module for Express Skeleton

Usage no npm install needed!

<script type="module">
  import vpSolutionsExpressSkeletonCryptoModule from 'https://cdn.skypack.dev/@vp_solutions/express-skeleton-crypto-module';


Crypto module for @vp_solutions/express-skeleton

Module description

Crypto module provide Service for managing users' passwords using BCrypt.

Example of usage with Inversify IoC container:

Crypto module is inversify container module that contain instance of BCrypt Service. For adding it in your project you have to import getCryptoModule() function which returns container module. Then just load this module into your app container and use provided by module dependencies.

// app-container.ts
import { Container } from 'inversify';
import { getCryptoModule } from '@vp_solutions/express-skeleton-crypto-module'

const appContainer = new Container();

// somewhere in your app
import { BCRYPT_SERVICE, IUserRepository } from '@vp_solutions/express-skeleton-crypto-module'
// import another dependencies

const user = await appContainer.get<IUserRepository>(USER_REPOSITORY).getUserByEmail(email);

if (!user) {
  throw new Error('User not found.');

if (! await appContainer.get<IBcryptService>(BCRYPT_SERVICE).isValidHash(password, user.password)) {
  throw new Error('Invalid user credentials.');