Finishing the Application
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:
Get Practical Microservices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.