September 2018
Intermediate to advanced
764 pages
20h 6m
English
First, let's install it as a development dependency:
$ yarn add bcryptjs --dev
Then, import the genSaltSync and hashSync methods from the bcryptjs module and use them to generate a salt and digest. We will also store the salt and digest in the context to help us make assertions in subsequent steps:
import { genSaltSync, hashSync } from 'bcryptjs';...async function createUser() { ... user.password = crypto.randomBytes(32).toString('hex'); user.salt = genSaltSync(10); user.digest = hashSync(user.password, user.salt); const result = await client.index({ index, type, refresh, body: { email: user.email, digest: user.digest, }, }); ...}
Read now
Unlock full access