April 2020
Intermediate to advanced
292 pages
6h 50m
English
Back to actions.registerUser, we have two steps left. hashPassword and writeRegisterCommand. Here is hashPassword:
| | const bcrypt = require('bcrypt') |
| | |
| | // We could pull this out into an environment variable, but we don't |
| | const SALT_ROUNDS = 10 |
| | function hashPassword (context) { |
| | return bcrypt |
| | .hash(context.attributes.password, SALT_ROUNDS) |
| | .then(passwordHash => { |
| | context.passwordHash = passwordHash |
| | |
| | return context |
| | }) |
| | } |
| | |
| | module.exports = hashPassword |
It uses bcrypt[49] to hash the password and attaches the hash at context.passwordHash.
Now that everything has checked out, we can finally write the command:
Read now
Unlock full access